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

Commit

Permalink
Fix handling of dedented continuation lines. (#472)
Browse files Browse the repository at this point in the history
* Fix handling of dedented continuation lines.

- Dedent the function definition before parsing it.
- Join continued-lines before attempting to parse the docstring.

* Update release notes

Co-authored-by: Sambhav Kothari <sambhavs.email@gmail.com>
  • Loading branch information
anntzer and samj1912 committed Aug 6, 2020
1 parent 6df2581 commit b0f7d62
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 4 deletions.
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 descriptions in docstrings
(#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

0 comments on commit b0f7d62

Please sign in to comment.