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

Commit 4d27748

Browse files
authored
Fix the AttributeError bug when parsing parameter lists in a class docstring (#436)
* Fix the AttributeError bug reported in #435. * Added release notes.
1 parent d1c06c6 commit 4d27748

File tree

3 files changed

+33
-9
lines changed

3 files changed

+33
-9
lines changed

docs/release_notes.rst

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,14 @@ Release Notes
44
**pydocstyle** version numbers follow the
55
`Semantic Versioning <http://semver.org/>`_ specification.
66

7+
5.0.1 - December 9th, 2019
8+
--------------------------
9+
10+
Bug Fixes
11+
12+
* Fixed an issue where AttributeError was raised when parsing the parameter
13+
section of a class docstring (#434, #436).
14+
715
5.0.0 - December 9th, 2019
816
--------------------------
917

src/pydocstyle/checker.py

Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -758,15 +758,16 @@ def _check_missing_args(docstring_args, definition):
758758
D417 with a list of missing arguments.
759759
760760
"""
761-
function_args = get_function_args(definition.source)
762-
# If the method isn't static, then we skip the first
763-
# positional argument as it is `cls` or `self`
764-
if definition.kind == 'method' and not definition.is_static:
765-
function_args = function_args[1:]
766-
missing_args = set(function_args) - docstring_args
767-
if missing_args:
768-
yield violations.D417(", ".join(sorted(missing_args)),
769-
definition.name)
761+
if isinstance(definition, Function):
762+
function_args = get_function_args(definition.source)
763+
# If the method isn't static, then we skip the first
764+
# positional argument as it is `cls` or `self`
765+
if definition.kind == 'method' and not definition.is_static:
766+
function_args = function_args[1:]
767+
missing_args = set(function_args) - docstring_args
768+
if missing_args:
769+
yield violations.D417(", ".join(sorted(missing_args)),
770+
definition.name)
770771

771772

772773
@classmethod

src/tests/test_cases/test.py

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -435,5 +435,20 @@ def bad_google_string(): # noqa: D400
435435
"""Test a valid something"""
436436

437437

438+
# This is reproducing a bug where AttributeError is raised when parsing class
439+
# parameters as functions for Google / Numpy conventions.
440+
class Blah: # noqa: D203,D213
441+
"""A Blah.
442+
443+
Parameters
444+
----------
445+
x : int
446+
447+
"""
448+
449+
def __init__(self, x):
450+
pass
451+
452+
438453
expect(os.path.normcase(__file__ if __file__[-1] != 'c' else __file__[:-1]),
439454
'D100: Missing docstring in public module')

0 commit comments

Comments
 (0)