Skip to content

Commit

Permalink
Improve DOC403 message (#129)
Browse files Browse the repository at this point in the history
  • Loading branch information
jsh9 committed May 29, 2024
1 parent af2c326 commit 2b0f1d8
Show file tree
Hide file tree
Showing 5 changed files with 69 additions and 5 deletions.
10 changes: 10 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,15 @@
# Change Log

## [0.4.2] - 2024-05-29

- Changed

- Improved the violation message of DOC403 to remind users to add a return
annotation

- Full diff
- https://github.com/jsh9/pydoclint/compare/0.4.1...0.4.2

## [0.4.1] - 2024-02-17

- Fixed
Expand Down
1 change: 1 addition & 0 deletions pydoclint/utils/violation.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@
403: ( # noqa: PAR001
'has a "Yields" section in the docstring, but there are no "yield"'
' statements, or the return annotation is not a Generator/Iterator/Iterable.'
' (Or it could be because the function lacks a return annotation.)'
),
404: 'yield type(s) in docstring not consistent with the return annotation.',
405: ( # noqa: PAR001
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.4.1
version = 0.4.2
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
35 changes: 35 additions & 0 deletions tests/data/edge_cases/10_absent_return_anno/numpy.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
# This edge case comes from: https://github.com/jsh9/pydoclint/issues/127

from __future__ import annotations

from typing import Iterable, Iterator


def f1(args: list):
"""ASDF
Arguments
---------
args: list
args
Yields
------
args: Iterable
"""
yield from args


def f2(args: list) -> Iterator[Iterable]:
"""ASDF
Arguments
---------
args: list
args
Yields
------
args: Iterable
"""
yield from args
26 changes: 22 additions & 4 deletions tests/test_main.py
Original file line number Diff line number Diff line change
Expand Up @@ -474,7 +474,8 @@ def testAllowInitDocstring(style: str) -> None:
'because __init__() cannot yield anything ',
'DOC403: Method `D.__init__` has a "Yields" section in the docstring, but '
'there are no "yield" statements, or the return annotation is not a '
'Generator/Iterator/Iterable. ',
'Generator/Iterator/Iterable. (Or it could be because the function lacks a '
'return annotation.) ',
]
assert list(map(str, violations)) == expected

Expand All @@ -499,7 +500,8 @@ def testYields(style: str) -> None:
'section does not exist or has 0 type(s).',
'DOC403: Method `A.method3` has a "Yields" section in the docstring, but '
'there are no "yield" statements, or the return annotation is not a '
'Generator/Iterator/Iterable. ',
'Generator/Iterator/Iterable. (Or it could be because the function lacks a '
'return annotation.) ',
'DOC402: Method `A.method6` has "yield" statements, but the docstring does '
'not have a "Yields" section ',
'DOC404: Method `A.method6` yield type(s) in docstring not consistent with '
Expand Down Expand Up @@ -528,7 +530,8 @@ def testYields(style: str) -> None:
'DOC201: Method `A.zipLists2` does not have a return section in docstring ',
'DOC403: Method `A.zipLists2` has a "Yields" section in the docstring, but '
'there are no "yield" statements, or the return annotation is not a '
'Generator/Iterator/Iterable. ',
'Generator/Iterator/Iterable. (Or it could be because the function lacks a '
'return annotation.) ',
'DOC404: Function `inner9a` yield type(s) in docstring not consistent with '
'the return annotation. The yield type (the 0th arg in '
'Generator[...]/Iterator[...]): str; docstring "yields" section types: '
Expand All @@ -541,7 +544,8 @@ def testYields(style: str) -> None:
'DOC201: Method `A.method9c` does not have a return section in docstring ',
'DOC403: Method `A.method9c` has a "Yields" section in the docstring, but '
'there are no "yield" statements, or the return annotation is not a '
'Generator/Iterator/Iterable. ',
'Generator/Iterator/Iterable. (Or it could be because the function lacks a '
'return annotation.) ',
'DOC404: Function `inner9c` yield type(s) in docstring not consistent with '
'the return annotation. The yield type (the 0th arg in '
'Generator[...]/Iterator[...]): str; docstring "yields" section types: '
Expand Down Expand Up @@ -1129,6 +1133,20 @@ def testNonAscii() -> None:
('08_return_section_parsing/google.py', {'style': 'google'}, []),
('09_double_quotes_in_Literal/google.py', {'style': 'google'}, []),
('09_double_quotes_in_Literal/numpy.py', {'style': 'numpy'}, []),
(
'10_absent_return_anno/numpy.py',
{'style': 'numpy'},
[
'DOC403: Function `f1` has a "Yields" section in the docstring, but there are '
'no "yield" statements, or the return annotation is not a '
'Generator/Iterator/Iterable. (Or it could be because the function lacks a '
'return annotation.) ',
'DOC404: Function `f1` yield type(s) in docstring not consistent with the '
'return annotation. Return annotation does not exist or is not '
'Generator[...]/Iterator[...]/Iterable[...], but docstring "yields" section '
'has 1 type(s).',
],
),
],
)
def testEdgeCases(
Expand Down

0 comments on commit 2b0f1d8

Please sign in to comment.