Skip to content

Commit

Permalink
Fix bug in type hint checking (#29)
Browse files Browse the repository at this point in the history
  • Loading branch information
jsh9 authored Jun 12, 2023
1 parent 0e4b55c commit 31e6a0b
Show file tree
Hide file tree
Showing 6 changed files with 54 additions and 9 deletions.
8 changes: 8 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,13 @@
# Change Log

## [0.0.10] - 2023-06-12

- Fixed
- Fixed a bug in checking type hints when the function signature only
contains star arguments
- Full diff
- https://github.com/jsh9/pydoclint/compare/0.0.9...0.0.10

## [0.0.9] - 2023-06-12

- Changed
Expand Down
11 changes: 3 additions & 8 deletions pydoclint/utils/arg.py
Original file line number Diff line number Diff line change
Expand Up @@ -223,19 +223,14 @@ def noTypeHints(self) -> bool:
return not self.hasTypeHintInAnyArg()

def hasTypeHintInAnyArg(self) -> bool:
"""
Check whether any arg has a type hint.
Start arguments (such as `*args` or `**kwargs`) are excluded because
they don't need to have type hints.
"""
return any(_.hasTypeHint() for _ in self.infoList if _.notStarArg())
"""Check whether any arg has a type hint"""
return any(_.hasTypeHint() for _ in self.infoList)

def hasTypeHintInAllArgs(self) -> bool:
"""
Check whether all args have a type hint.
Start arguments (such as `*args` or `**kwargs`) are excluded because
Star arguments (such as `*args` or `**kwargs`) are excluded because
they don't need to have type hints.
"""
return all(_.hasTypeHint() for _ in self.infoList if _.notStarArg())
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.0.9
version = 0.0.10
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
13 changes: 13 additions & 0 deletions tests/data/google/star_args/cases2.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
from typing import Dict, Tuple


class A:
def __init__(self, *args: Tuple, **kwargs: Dict) -> None:
"""
Do something.
Args:
*args: Args
**kwargs: Keyword args
"""
pass
16 changes: 16 additions & 0 deletions tests/data/numpy/star_args/cases2.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
from typing import Dict, Tuple


class A:
def __init__(self, *args: Tuple, **kwargs: Dict) -> None:
"""
Do something.
Parameters
----------
*args :
Args
**kwargs :
Keyword args
"""
pass
13 changes: 13 additions & 0 deletions tests/test_main.py
Original file line number Diff line number Diff line change
Expand Up @@ -428,6 +428,19 @@ def testStarsInArgumentList(style: str) -> None:
assert list(map(str, violations)) == expected


@pytest.mark.parametrize('style', ['numpy', 'google'])
def testStarsInArgumentList2(style: str) -> None:
violations = _checkFile(
filename=DATA_DIR / f'{style}/star_args/cases2.py',
typeHintsInSignature=True,
typeHintsInDocstring=False,
allowInitDocstring=True,
style=style,
)
expected = []
assert list(map(str, violations)) == expected


def testParsingErrors_google() -> None:
violations = _checkFile(
filename=DATA_DIR / 'google/parsing_errors/cases.py',
Expand Down

0 comments on commit 31e6a0b

Please sign in to comment.