diff --git a/CHANGELOG.md b/CHANGELOG.md index 7b7ab1b..8aa5d1d 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -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 diff --git a/pydoclint/visitor.py b/pydoclint/visitor.py index 9373248..e8de050 100644 --- a/pydoclint/visitor.py +++ b/pydoclint/visitor.py @@ -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: diff --git a/setup.cfg b/setup.cfg index c242d9b..8fc49f0 100644 --- a/setup.cfg +++ b/setup.cfg @@ -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 diff --git a/tests/data/google/yields/cases.py b/tests/data/google/yields/cases.py index 0289c81..db62421 100644 --- a/tests/data/google/yields/cases.py +++ b/tests/data/google/yields/cases.py @@ -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: @@ -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)) diff --git a/tests/data/numpy/yields/cases.py b/tests/data/numpy/yields/cases.py index 058e090..b322a04 100644 --- a/tests/data/numpy/yields/cases.py +++ b/tests/data/numpy/yields/cases.py @@ -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 @@ -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)) diff --git a/tests/data/sphinx/yields/cases.py b/tests/data/sphinx/yields/cases.py index e32a00d..68db30e 100644 --- a/tests/data/sphinx/yields/cases.py +++ b/tests/data/sphinx/yields/cases.py @@ -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 @@ -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)) diff --git a/tests/test_main.py b/tests/test_main.py index 7de6ca9..3f293fc 100644 --- a/tests/test_main.py +++ b/tests/test_main.py @@ -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', ]