diff --git a/CHANGELOG.md b/CHANGELOG.md index 0a98f08..2f8bf5e 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,12 @@ # Change Log +## [0.1.7] - 2023-08-15 + +- Fixed + - Correctly handle potentially unacceptable type hint formats +- Full diff + - https://github.com/jsh9/pydoclint/compare/0.1.6...0.1.7 + ## [0.1.6] - 2023-08-13 - Added diff --git a/pydoclint/utils/arg.py b/pydoclint/utils/arg.py index d0c408f..8872b7e 100644 --- a/pydoclint/utils/arg.py +++ b/pydoclint/utils/arg.py @@ -102,8 +102,16 @@ def _eq(cls, str1: str, str2: str) -> bool: # >>> "def", # >>> "ghi", # >>> ] - str1_: str = unparseAnnotation(ast.parse(stripQuotes(str1))) - str2_: str = unparseAnnotation(ast.parse(stripQuotes(str2))) + try: + str1_: str = unparseAnnotation(ast.parse(stripQuotes(str1))) + except SyntaxError: + str1_ = str1 + + try: + str2_: str = unparseAnnotation(ast.parse(stripQuotes(str2))) + except SyntaxError: + str2_ = str2 + return str1_ == str2_ diff --git a/setup.cfg b/setup.cfg index 07c7d3d..9be6804 100644 --- a/setup.cfg +++ b/setup.cfg @@ -1,6 +1,6 @@ [metadata] name = pydoclint -version = 0.1.6 +version = 0.1.7 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/edge_case_02_syntax_error_in_type_hints.py b/tests/data/edge_cases/edge_case_02_syntax_error_in_type_hints.py new file mode 100644 index 0000000..6ac7308 --- /dev/null +++ b/tests/data/edge_cases/edge_case_02_syntax_error_in_type_hints.py @@ -0,0 +1,34 @@ +# Related issue: https://github.com/jsh9/pydoclint/issues/59 + + +def func1(a='a'): + """ + Title + + Parameters + ---------- + a : str, default a + """ + pass + + +def func2(a='a'): + """ + Title + + Parameters + ---------- + a : str, default=a + """ + pass + + +def func3(a='a'): + """ + Title + + Parameters + ---------- + a : str, default: a + """ + pass diff --git a/tests/test_main.py b/tests/test_main.py index 93f6dd3..077f79e 100644 --- a/tests/test_main.py +++ b/tests/test_main.py @@ -833,6 +833,27 @@ def testNonAscii() -> None: 'filename, options, expectedViolations', [ ('edge_case_01.py', {'style': 'sphinx'}, []), + ( + 'edge_case_02_syntax_error_in_type_hints.py', + {'style': 'numpy'}, + [ + 'DOC106: Function `func1`: The option `--arg-type-hints-in-signature` is ' + '`True` 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 ', + 'DOC105: Function `func1`: Argument names match, but type hints do not match ', + 'DOC106: Function `func2`: The option `--arg-type-hints-in-signature` is ' + '`True` 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 ', + 'DOC105: Function `func2`: Argument names match, but type hints do not match ', + 'DOC106: Function `func3`: The option `--arg-type-hints-in-signature` is ' + '`True` but there are no argument type hints in the signature ', + 'DOC107: Function `func3`: The option `--arg-type-hints-in-signature` is ' + '`True` but not all args in the signature have type hints ', + 'DOC105: Function `func3`: Argument names match, but type hints do not match ', + ], + ), ], ) def testEdgeCases(