Skip to content

Commit

Permalink
Don't report DOC109 if arg list is empty (#146)
Browse files Browse the repository at this point in the history
  • Loading branch information
jsh9 authored Jun 27, 2024
1 parent 4dd1667 commit 4d0293a
Show file tree
Hide file tree
Showing 6 changed files with 17 additions and 23 deletions.
6 changes: 5 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,15 +1,19 @@
# 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
- When a class has a short docstring (and
`--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
Expand Down
3 changes: 3 additions & 0 deletions pydoclint/utils/arg.py
Original file line number Diff line number Diff line change
Expand Up @@ -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"""
Expand Down
9 changes: 8 additions & 1 deletion pydoclint/visitor.py
Original file line number Diff line number Diff line change
Expand Up @@ -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():
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.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
Expand Down
2 changes: 0 additions & 2 deletions tests/test_baseline.py
Original file line number Diff line number Diff line change
Expand Up @@ -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]].',
Expand Down
18 changes: 0 additions & 18 deletions tests/test_main.py
Original file line number Diff line number Diff line change
Expand Up @@ -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 '
Expand Down Expand Up @@ -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 '
Expand All @@ -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 '
Expand Down Expand Up @@ -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 '
Expand Down Expand Up @@ -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 ). '
Expand Down Expand Up @@ -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 ). '
Expand Down Expand Up @@ -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 '
Expand All @@ -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 '
Expand Down

0 comments on commit 4d0293a

Please sign in to comment.