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

Fix handling of dedented continuation lines. #472

Merged
merged 3 commits into from Aug 6, 2020
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
2 changes: 2 additions & 0 deletions docs/release_notes.rst
Expand Up @@ -20,6 +20,8 @@ Bug Fixes
The bug caused some argument names to go unreported in D417 (#448).
* Fixed an issue where skipping errors on module level docstring via #noqa
failed when there where more prior comments (#446).
* Support backslash-continued parameter descriptions in Numpy-style docstrings
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Isn't it doing this for more than just numpy parameter descriptions at this point?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

should we update this?

(#472).


5.0.2 - January 8th, 2020
Expand Down
8 changes: 6 additions & 2 deletions src/pydocstyle/checker.py
Expand Up @@ -278,7 +278,9 @@ def check_indent(self, definition, docstring):
indent = self._get_docstring_indent(definition, docstring)
lines = docstring.split('\n')
if len(lines) > 1:
lines = lines[1:] # First line does not need indent.
# First line and line continuations need no indent.
lines = [line for i, line in enumerate(lines)
if i and not lines[i-1].endswith('\\')]
indents = [leading_space(l) for l in lines if not is_blank(l)]
if set(' \t') == set(''.join(indents) + indent):
yield violations.D206()
Expand Down Expand Up @@ -703,7 +705,9 @@ def _check_parameters_section(docstring, definition, context):
"""
docstring_args = set()
section_level_indent = leading_space(context.line)
content = context.following_lines
# Join line continuations, then resplit by line.
content = (
'\n'.join(context.following_lines).replace('\\\n', '').split('\n'))
for current_line, next_line in zip(content, content[1:]):
# All parameter definitions in the Numpy parameters
# section must be at the same indent level as the section
Expand Down
9 changes: 7 additions & 2 deletions src/tests/test_cases/sections.py
Expand Up @@ -389,7 +389,6 @@ def test_missing_docstring_another(skip, verbose): # noqa: D213, D407
@expect("D417: Missing argument descriptions in the docstring "
"(argument(s) y are missing descriptions in "
"'test_missing_numpy_args' docstring)")
@expect("D207: Docstring is under-indented")
def test_missing_numpy_args(_private_arg=0, x=1, y=2): # noqa: D406, D407
"""Toggle the gizmo.

Expand All @@ -405,13 +404,19 @@ def test_missing_numpy_args(_private_arg=0, x=1, y=2): # noqa: D406, D407
class TestNumpy: # noqa: D203
"""Test class."""

def test_method(self, test, another_test, _, x=1, y=2, _private_arg=1): # noqa: D213, D407
def test_method(self, test, another_test, z, _, x=1, y=2, _private_arg=1): # noqa: D213, D407
"""Test a valid args section.

Some long string with a \
line continuation.

Parameters
----------
test, another_test
Some parameters without type.
z : some parameter with a very long type description that requires a \
line continuation.
But no further description.
x, y : int
Some integer parameters.

Expand Down