Skip to content
This repository has been archived by the owner on Nov 3, 2023. It is now read-only.

Commit

Permalink
Fix the AttributeError bug when parsing parameter lists in a class do…
Browse files Browse the repository at this point in the history
…cstring (#436)

* Fix the AttributeError bug reported in #435.

* Added release notes.
  • Loading branch information
Nurdok authored Dec 9, 2019
1 parent d1c06c6 commit 4d27748
Show file tree
Hide file tree
Showing 3 changed files with 33 additions and 9 deletions.
8 changes: 8 additions & 0 deletions docs/release_notes.rst
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,14 @@ Release Notes
**pydocstyle** version numbers follow the
`Semantic Versioning <http://semver.org/>`_ 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
--------------------------

Expand Down
19 changes: 10 additions & 9 deletions src/pydocstyle/checker.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
15 changes: 15 additions & 0 deletions src/tests/test_cases/test.py
Original file line number Diff line number Diff line change
Expand Up @@ -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')

0 comments on commit 4d27748

Please sign in to comment.