Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Don't check type hints for DOC103 #86

Merged
merged 2 commits into from
Oct 12, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 8 additions & 2 deletions pydoclint/utils/arg.py
Original file line number Diff line number Diff line change
Expand Up @@ -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"""
Expand Down
10 changes: 8 additions & 2 deletions pydoclint/visitor.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
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.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
Expand Down
14 changes: 14 additions & 0 deletions tests/data/edge_cases/06_no_type_hints_in_doc/numpy.py
Original file line number Diff line number Diff line change
@@ -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
18 changes: 15 additions & 3 deletions tests/test_main.py
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down Expand Up @@ -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(
Expand Down