From 4d0293a1ab4793d61a840e8746cdf7e62c892f70 Mon Sep 17 00:00:00 2001 From: jsh9 <25124332+jsh9@users.noreply.github.com> Date: Wed, 26 Jun 2024 18:42:44 -0700 Subject: [PATCH] Don't report DOC109 if arg list is empty (#146) --- CHANGELOG.md | 6 +++++- pydoclint/utils/arg.py | 3 +++ pydoclint/visitor.py | 9 ++++++++- setup.cfg | 2 +- tests/test_baseline.py | 2 -- tests/test_main.py | 18 ------------------ 6 files changed, 17 insertions(+), 23 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index a86e3ab..b49653f 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,8 +1,9 @@ # Change Log -## [unpublished] +## [0.5.2] - 2024-06-26 - Changed + - Pinned to a higher version (0.0.9) of docstring_parser_fork - Relaxed class attribute checking logic - When a class has no docstring, no DOC6xx violations will be reported @@ -10,6 +11,9 @@ `--skip-checking-short-docstrings`) is set to `True`, no DOC6xx violations will be reported +- Full diff + - https://github.com/jsh9/pydoclint/compare/0.5.1...0.5.2 + ## [0.5.1] - 2024-06-24 - Fixed diff --git a/pydoclint/utils/arg.py b/pydoclint/utils/arg.py index 79e6efa..2427162 100644 --- a/pydoclint/utils/arg.py +++ b/pydoclint/utils/arg.py @@ -181,6 +181,9 @@ def __eq__(self, other: 'ArgList') -> bool: return self.infoList == other.infoList + def __len__(self) -> int: + return len(self.infoList) + @property def isEmpty(self) -> bool: """Whether the arg list is empty""" diff --git a/pydoclint/visitor.py b/pydoclint/visitor.py index c7494ca..7159901 100644 --- a/pydoclint/visitor.py +++ b/pydoclint/visitor.py @@ -418,7 +418,14 @@ def checkArguments( # noqa: C901 if not self.argTypeHintsInSignature and funcArgs.hasTypeHintInAnyArg(): violations.append(v108) - if self.argTypeHintsInDocstring and docArgs.noTypeHints(): + if self.argTypeHintsInDocstring and ( + # A non-empty arg list is the pre-requisite for reporting DOC109. + # Otherwise, the error message of DOC109 would not make sense. + # ("The option `--arg-type-hints-in-docstring` is `True` but + # there are no type hints in the docstring arg list") + len(docArgs) > 0 + and docArgs.noTypeHints() + ): violations.append(v109) if self.argTypeHintsInDocstring and not docArgs.hasTypeHintInAllArgs(): diff --git a/setup.cfg b/setup.cfg index 38e08e3..b77e9b8 100644 --- a/setup.cfg +++ b/setup.cfg @@ -1,6 +1,6 @@ [metadata] name = pydoclint -version = 0.5.1 +version = 0.5.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 diff --git a/tests/test_baseline.py b/tests/test_baseline.py index 1100eac..488c82d 100644 --- a/tests/test_baseline.py +++ b/tests/test_baseline.py @@ -55,8 +55,6 @@ def bad_docstring_func(arg1: str, arg2: list[int]) -> bool: expectedNewViolations = [ 'DOC101: Function `bad_docstring_func`: Docstring contains fewer arguments than in function signature. ', - 'DOC109: Function `bad_docstring_func`: The option `--arg-type-hints-in-docstring` is `True` ' - 'but there are no type hints in the docstring arg list ', 'DOC103: Function `bad_docstring_func`: 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: [arg1: str, arg2: list[int]].', diff --git a/tests/test_main.py b/tests/test_main.py index dee0421..c1d2398 100644 --- a/tests/test_main.py +++ b/tests/test_main.py @@ -19,8 +19,6 @@ def pythonVersionBelow310(): expectedViolations_True = [ 'DOC101: Method `MyClass.func1_3`: Docstring contains fewer arguments than in ' 'function signature. ', - 'DOC109: Method `MyClass.func1_3`: The option `--arg-type-hints-in-docstring` is `True` ' - 'but there are no type hints in the docstring arg list ', 'DOC103: Method `MyClass.func1_3`: 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 ' @@ -55,8 +53,6 @@ def pythonVersionBelow310(): 'do not match: arg1, arg2', 'DOC101: Function `func72`: Docstring contains fewer arguments than in ' 'function signature. ', - 'DOC109: Function `func72`: The option `--arg-type-hints-in-docstring` is `True` ' - 'but there are no type hints in the docstring arg list ', 'DOC103: Function `func72`: 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 ' @@ -66,8 +62,6 @@ def pythonVersionBelow310(): expectedViolations_False = [ 'DOC101: Method `MyClass.func1_3`: Docstring contains fewer arguments than in ' 'function signature. ', - 'DOC109: Method `MyClass.func1_3`: The option `--arg-type-hints-in-docstring` is `True` ' - 'but there are no type hints in the docstring arg list ', 'DOC103: Method `MyClass.func1_3`: 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 ' @@ -98,8 +92,6 @@ def pythonVersionBelow310(): 'these args do not match: arg1, arg2', 'DOC101: Function `func72`: Docstring contains fewer arguments than in ' 'function signature. ', - 'DOC109: Function `func72`: The option `--arg-type-hints-in-docstring` is `True` ' - 'but there are no type hints in the docstring arg list ', 'DOC103: Function `func72`: 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 ' @@ -193,9 +185,6 @@ def testClassAttributes( 'correctly document class attributes.)', 'DOC101: Method `MyClass2.__init__`: Docstring contains fewer arguments than ' 'in function signature. ', - 'DOC109: Method `MyClass2.__init__`: The option ' - '`--arg-type-hints-in-docstring` is `True` but there are no type hints in the ' - 'docstring arg list ', 'DOC103: Method `MyClass2.__init__`: Docstring arguments are different from ' 'function arguments. (Or could be other formatting issues: ' 'https://jsh9.github.io/pydoclint/violation_codes.html#notes-on-doc103 ). ' @@ -241,9 +230,6 @@ def testClassAttributes( 'in these args do not match: arg2', 'DOC101: Method `MyClass2.__init__`: Docstring contains fewer arguments than ' 'in function signature. ', - 'DOC109: Method `MyClass2.__init__`: The option ' - '`--arg-type-hints-in-docstring` is `True` but there are no type hints in the ' - 'docstring arg list ', 'DOC103: Method `MyClass2.__init__`: Docstring arguments are different from ' 'function arguments. (Or could be other formatting issues: ' 'https://jsh9.github.io/pydoclint/violation_codes.html#notes-on-doc103 ). ' @@ -501,8 +487,6 @@ def _tweakViolationMsgForFunctions(expectedViolationsCopy: List[str]) -> None: 'but there are no argument type hints in the signature ', 'DOC107: Function `func1`: The option `--arg-type-hints-in-signature` is `True` ' 'but not all args in the signature have type hints ', - 'DOC109: Function `func1`: The option `--arg-type-hints-in-docstring` is `True` ' - 'but there are no type hints in the docstring arg list ', 'DOC103: Function `func1`: 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 ' @@ -517,8 +501,6 @@ def _tweakViolationMsgForFunctions(expectedViolationsCopy: List[str]) -> None: 'but there are no argument type hints in the signature ', 'DOC107: Function `func2`: The option `--arg-type-hints-in-signature` is `True` ' 'but not all args in the signature have type hints ', - 'DOC109: Function `func2`: The option `--arg-type-hints-in-docstring` is `True` ' - 'but there are no type hints in the docstring arg list ', 'DOC103: Function `func2`: 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 '