Skip to content

Commit

Permalink
Fix bug with unparsing yield types
Browse files Browse the repository at this point in the history
  • Loading branch information
jsh9 committed Aug 24, 2023
1 parent 1d60f54 commit 0d03618
Show file tree
Hide file tree
Showing 7 changed files with 51 additions and 9 deletions.
8 changes: 8 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,13 @@
# Change Log

## [0.2.4] - 2023-08-24

- Fixed
- A bug with unparsing yield types
(https://github.com/jsh9/pydoclint/issues/75#issuecomment-1691398673)
- Full diff
- https://github.com/jsh9/pydoclint/compare/0.2.3...0.2.4

## [0.2.3] - 2023-08-24

- Fixed
Expand Down
6 changes: 2 additions & 4 deletions pydoclint/visitor.py
Original file line number Diff line number Diff line change
Expand Up @@ -671,18 +671,16 @@ def checkYields( # noqa: C901
yieldType: str

if sys.version_info >= (3, 9):
yieldType = (
yieldType = unparseAnnotation(
ast.parse(returnAnno.annotation)
.body[0]
.value.slice.elts[0]
.id
)
else:
yieldType = (
yieldType = unparseAnnotation(
ast.parse(returnAnno.annotation)
.body[0]
.value.slice.value.elts[0] # here is different
.id
)

except Exception:
Expand Down
2 changes: 1 addition & 1 deletion setup.cfg
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[metadata]
name = pydoclint
version = 0.2.3
version = 0.2.4
description = A Python docstring linter that checks arguments, returns, yields, and raises sections
long_description = file: README.md
long_description_content_type = text/markdown
Expand Down
13 changes: 12 additions & 1 deletion tests/data/google/yields/cases.py
Original file line number Diff line number Diff line change
Expand Up @@ -284,7 +284,7 @@ def inner9d(inner_arg1: List[int]) -> Iterable[str]:

yield inner9d(arg1)

def method10(self, n: int) -> Generator[str, None, None]:
def method10a(self, n: int) -> Generator[str, None, None]:
"""Description
Args:
Expand All @@ -294,3 +294,14 @@ def method10(self, n: int) -> Generator[str, None, None]:
int: Description
"""
yield from range(n)

def method10b(self, n: int) -> Generator[tuple[float, ...], None, None]:
"""Foo
Args:
n (int): Description.
Yields:
tuple[float, ...]: Description.
"""
yield from ((*self.bar, i) for i in range(self.baz))
17 changes: 16 additions & 1 deletion tests/data/numpy/yields/cases.py
Original file line number Diff line number Diff line change
Expand Up @@ -342,7 +342,7 @@ def inner9d(inner_arg1: List[int]) -> Iterable[str]:

yield inner9d(arg1)

def method10(self, n: int) -> Generator[str, None, None]:
def method10a(self, n: int) -> Generator[str, None, None]:
"""Description
Parameters
Expand All @@ -356,3 +356,18 @@ def method10(self, n: int) -> Generator[str, None, None]:
Description
"""
yield from range(n)

def method10b(self, n: int) -> Generator[tuple[float, ...], None, None]:
"""Foo
Parameters
----------
n : int
Description.
Yields
------
tuple[float, ...]
Description.
"""
yield from ((*self.bar, i) for i in range(self.baz))
12 changes: 11 additions & 1 deletion tests/data/sphinx/yields/cases.py
Original file line number Diff line number Diff line change
Expand Up @@ -272,7 +272,7 @@ def inner9d(inner_arg1: List[int]) -> Iterable[str]:

yield inner9d(arg1)

def method10(self, n: int) -> Generator[str, None, None]:
def method10a(self, n: int) -> Generator[str, None, None]:
"""Description
:param n: Description
Expand All @@ -281,3 +281,13 @@ def method10(self, n: int) -> Generator[str, None, None]:
:rtype: int
"""
yield from range(n)

def method10b(self, n: int) -> Generator[tuple[float, ...], None, None]:
"""Foo
:param n: Description
:type n: int
:yield: Description
:rtype: tuple[float, ...]
"""
yield from ((*self.bar, i) for i in range(self.baz))
2 changes: 1 addition & 1 deletion tests/test_main.py
Original file line number Diff line number Diff line change
Expand Up @@ -632,7 +632,7 @@ def testYields(style: str) -> None:
'DOC404: Function `inner9d` yield type(s) in docstring not consistent with '
'the return annotation. Return annotation exists, but docstring "yields" '
'section does not exist or has 0 type(s).',
'DOC404: Method `A.method10` yield type(s) in docstring not consistent with '
'DOC404: Method `A.method10a` yield type(s) in docstring not consistent with '
'the return annotation. The yield type (the 0th arg in Generator[...]): str; '
'docstring "yields" section types: int',
]
Expand Down

0 comments on commit 0d03618

Please sign in to comment.