Skip to content

Commit

Permalink
Fix annotation unparsing bug (#132)
Browse files Browse the repository at this point in the history
  • Loading branch information
jsh9 authored Jun 23, 2024
1 parent 2c4337c commit a5e24e6
Show file tree
Hide file tree
Showing 6 changed files with 20 additions and 15 deletions.
5 changes: 5 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,10 @@
# Change Log

## [unpublished]

- Fixed
- Fixed a bug in unparsing annotations when checking class attributes

## [0.5.0] - 2024-06-22

- Added
Expand Down
2 changes: 1 addition & 1 deletion pydoclint/utils/arg.py
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,7 @@ def fromAstAnnAssign(cls, astAnnAssign: ast.AnnAssign) -> 'Arg':
"""Construct an Arg object from a Python ast.AnnAssign object"""
return Arg(
name=astAnnAssign.target.id,
typeHint=astAnnAssign.annotation.id,
typeHint=unparseAnnotation(astAnnAssign.annotation),
)

@classmethod
Expand Down
8 changes: 4 additions & 4 deletions tests/data/google/class_attributes/cases.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,15 +3,15 @@ class MyClass1:
A class that holds some things.
Attributes:
name (str): The name
indices (int): The indices
name (str | bool | None): The name
indices (pd.DataFrame): The indices
Args:
arg1 (float): The information
"""

name: str
index: int
name: str | bool | None
index: pd.DataFrame

hello: int = 1
world: dict
Expand Down
8 changes: 4 additions & 4 deletions tests/data/numpy/class_attributes/cases.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,9 @@ class MyClass1:
Attributes
----------
name : str
name : str | bool | None
The name
indices : int
indices : pd.DataFrame
The indices
Parameters
Expand All @@ -15,8 +15,8 @@ class MyClass1:
The information
"""

name: str
index: int
name: str | bool | None
index: pd.DataFrame

hello: int = 1
world: dict
Expand Down
8 changes: 4 additions & 4 deletions tests/data/sphinx/class_attributes/cases.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,15 +3,15 @@ class MyClass1:
A class that holds some things.
:attr name: The name
:type name: str
:type name: str | bool | None
:attr indices: The indices
:type indices: int
:type indices: pd.DataFrame
:param arg1: The information
:type arg1: float
"""

name: str
index: int
name: str | bool | None
index: pd.DataFrame

hello: int = 1
world: dict
Expand Down
4 changes: 2 additions & 2 deletions tests/test_main.py
Original file line number Diff line number Diff line change
Expand Up @@ -169,8 +169,8 @@ def testClassAttributes(
'actual class attributes. (Or could be other formatting issues: '
'https://jsh9.github.io/pydoclint/violation_codes.html#notes-on-doc103 ). '
'Attributes in the class definition but not in the docstring: [hello: int, '
'index: int, world: dict]. Arguments in the docstring but not in the actual '
'class attributes: [indices: int].',
'index: pd.DataFrame, world: dict]. Arguments in the docstring but not in the '
'actual class attributes: [indices: pd.DataFrame].',
'DOC105: Method `MyClass1.__init__`: Argument names match, but type hints in '
'these args do not match: arg1',
'DOC105: Method `MyClass1.do_something`: Argument names match, but type hints '
Expand Down

0 comments on commit a5e24e6

Please sign in to comment.