diff --git a/pydoclint/utils/arg.py b/pydoclint/utils/arg.py index 733d43d..4627c8b 100644 --- a/pydoclint/utils/arg.py +++ b/pydoclint/utils/arg.py @@ -238,9 +238,15 @@ def equals( return verdict # noqa: R504 - def subtract(self, other: 'ArgList') -> Set[Arg]: + def subtract(self, other: 'ArgList', checkTypeHint=True) -> Set[Arg]: """Find the args that are in this object but not in `other`.""" - return set(self.infoList) - set(other.infoList) + if checkTypeHint: + return set(self.infoList) - set(other.infoList) + + argNamesSelf = {_.name for _ in self.infoList} + argNamesOther = {_.name for _ in other.infoList} + diffArgName = argNamesSelf - argNamesOther + return {Arg(name=_, typeHint=self.lookup[_]) for _ in diffArgName} def noTypeHints(self) -> bool: """Check whether none of the args have type hints""" diff --git a/pydoclint/visitor.py b/pydoclint/visitor.py index 37e66c6..b7daa88 100644 --- a/pydoclint/visitor.py +++ b/pydoclint/visitor.py @@ -421,8 +421,14 @@ def checkArguments( # noqa: C901 violations.append(v104) violations.append(v105) else: - argsInFuncNotInDoc: Set[Arg] = funcArgs.subtract(docArgs) - argsInDocNotInFunc: Set[Arg] = docArgs.subtract(funcArgs) + argsInFuncNotInDoc: Set[Arg] = funcArgs.subtract( + docArgs, + checkTypeHint=False, + ) + argsInDocNotInFunc: Set[Arg] = docArgs.subtract( + funcArgs, + checkTypeHint=False, + ) msgPostfixParts: List[str] = [] if argsInFuncNotInDoc: diff --git a/setup.cfg b/setup.cfg index 0b613b7..4d658b2 100644 --- a/setup.cfg +++ b/setup.cfg @@ -1,6 +1,6 @@ [metadata] name = pydoclint -version = 0.3.3 +version = 0.3.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/edge_cases/06_no_type_hints_in_doc/numpy.py b/tests/data/edge_cases/06_no_type_hints_in_doc/numpy.py new file mode 100644 index 0000000..45e1dfe --- /dev/null +++ b/tests/data/edge_cases/06_no_type_hints_in_doc/numpy.py @@ -0,0 +1,14 @@ +def f(x: int, y: int, z: int) -> None: + """ + Run f(). + + From issue: https://github.com/jsh9/pydoclint/issues/85 + + Parameters + ---------- + y + y + z + z + """ + pass diff --git a/tests/test_main.py b/tests/test_main.py index 4fbb1d3..8fb0b93 100644 --- a/tests/test_main.py +++ b/tests/test_main.py @@ -718,9 +718,9 @@ def testStarsInArgumentList(style: str) -> None: 'function signature. ', 'DOC103: Function `func7`: Docstring arguments are different from function ' 'arguments. (Or could be other formatting issues: ' - 'https://jsh9.github.io/pydoclint/violation_codes.html#notes-on-doc103 ). Arguments in the function signature but not in the ' - 'docstring: [**kwargs: , *args: , arg1: float, arg2: str]. Arguments in the ' - 'docstring but not in the function signature: [arg1: int, arg2: dict].', + 'https://jsh9.github.io/pydoclint/violation_codes.html#notes-on-doc103 ). ' + 'Arguments in the function signature but not in the docstring: [**kwargs: , ' + '*args: ].', ] assert list(map(str, violations)) == expected @@ -1084,6 +1084,18 @@ def testNonAscii() -> None: ('05_escape_char/google.py', {'style': 'google'}, []), ('05_escape_char/numpy.py', {'style': 'numpy'}, []), ('05_escape_char/sphinx.py', {'style': 'sphinx'}, []), + ( + '06_no_type_hints_in_doc/numpy.py', + {'style': 'numpy', 'argTypeHintsInDocstring': False}, + [ + 'DOC101: Function `f`: Docstring contains fewer arguments than in function ' + 'signature. ', + 'DOC103: Function `f`: Docstring arguments are different from function ' + 'arguments. (Or could be other formatting issues: ' + 'https://jsh9.github.io/pydoclint/violation_codes.html#notes-on-doc103 ). ' + 'Arguments in the function signature but not in the docstring: [x: int].', + ], + ), ], ) def testEdgeCases(