From b5ec3820a860c147e8a78c0baaba3980940a8ba0 Mon Sep 17 00:00:00 2001 From: Amir Rachum Date: Mon, 9 Dec 2019 21:46:27 +0200 Subject: [PATCH 1/2] Fix the AttributeError bug reported in #435. --- src/pydocstyle/checker.py | 19 ++++++++++--------- src/tests/test_cases/test.py | 15 +++++++++++++++ 2 files changed, 25 insertions(+), 9 deletions(-) diff --git a/src/pydocstyle/checker.py b/src/pydocstyle/checker.py index 52626fe9..6ecf8093 100644 --- a/src/pydocstyle/checker.py +++ b/src/pydocstyle/checker.py @@ -758,15 +758,16 @@ def _check_missing_args(docstring_args, definition): D417 with a list of missing arguments. """ - function_args = get_function_args(definition.source) - # If the method isn't static, then we skip the first - # positional argument as it is `cls` or `self` - if definition.kind == 'method' and not definition.is_static: - function_args = function_args[1:] - missing_args = set(function_args) - docstring_args - if missing_args: - yield violations.D417(", ".join(sorted(missing_args)), - definition.name) + if isinstance(definition, Function): + function_args = get_function_args(definition.source) + # If the method isn't static, then we skip the first + # positional argument as it is `cls` or `self` + if definition.kind == 'method' and not definition.is_static: + function_args = function_args[1:] + missing_args = set(function_args) - docstring_args + if missing_args: + yield violations.D417(", ".join(sorted(missing_args)), + definition.name) @classmethod diff --git a/src/tests/test_cases/test.py b/src/tests/test_cases/test.py index ce74854c..20b81fce 100644 --- a/src/tests/test_cases/test.py +++ b/src/tests/test_cases/test.py @@ -435,5 +435,20 @@ def bad_google_string(): # noqa: D400 """Test a valid something""" +# This is reproducing a bug where AttributeError is raised when parsing class +# parameters as functions for Google / Numpy conventions. +class Blah: # noqa: D203,D213 + """A Blah. + + Parameters + ---------- + x : int + + """ + + def __init__(self, x): + pass + + expect(os.path.normcase(__file__ if __file__[-1] != 'c' else __file__[:-1]), 'D100: Missing docstring in public module') From f89df641919044912b6c8b5784e2c941eaba9044 Mon Sep 17 00:00:00 2001 From: Amir Rachum Date: Mon, 9 Dec 2019 21:53:52 +0200 Subject: [PATCH 2/2] Added release notes. --- docs/release_notes.rst | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/docs/release_notes.rst b/docs/release_notes.rst index 9b9cedf7..5d6daf2f 100644 --- a/docs/release_notes.rst +++ b/docs/release_notes.rst @@ -4,6 +4,14 @@ Release Notes **pydocstyle** version numbers follow the `Semantic Versioning `_ specification. +5.0.1 - December 9th, 2019 +-------------------------- + +Bug Fixes + +* Fixed an issue where AttributeError was raised when parsing the parameter + section of a class docstring (#434, #436). + 5.0.0 - December 9th, 2019 --------------------------