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

Commit b0f7d62

Browse files
anntzersambhav
andauthored
Fix handling of dedented continuation lines. (#472)
* 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>
1 parent 6df2581 commit b0f7d62

File tree

3 files changed

+15
-4
lines changed

3 files changed

+15
-4
lines changed

docs/release_notes.rst

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,8 @@ Bug Fixes
2020
The bug caused some argument names to go unreported in D417 (#448).
2121
* Fixed an issue where skipping errors on module level docstring via #noqa
2222
failed when there where more prior comments (#446).
23+
* Support backslash-continued descriptions in docstrings
24+
(#472).
2325

2426

2527
5.0.2 - January 8th, 2020

src/pydocstyle/checker.py

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -278,7 +278,9 @@ def check_indent(self, definition, docstring):
278278
indent = self._get_docstring_indent(definition, docstring)
279279
lines = docstring.split('\n')
280280
if len(lines) > 1:
281-
lines = lines[1:] # First line does not need indent.
281+
# First line and line continuations need no indent.
282+
lines = [line for i, line in enumerate(lines)
283+
if i and not lines[i-1].endswith('\\')]
282284
indents = [leading_space(l) for l in lines if not is_blank(l)]
283285
if set(' \t') == set(''.join(indents) + indent):
284286
yield violations.D206()
@@ -703,7 +705,9 @@ def _check_parameters_section(docstring, definition, context):
703705
"""
704706
docstring_args = set()
705707
section_level_indent = leading_space(context.line)
706-
content = context.following_lines
708+
# Join line continuations, then resplit by line.
709+
content = (
710+
'\n'.join(context.following_lines).replace('\\\n', '').split('\n'))
707711
for current_line, next_line in zip(content, content[1:]):
708712
# All parameter definitions in the Numpy parameters
709713
# section must be at the same indent level as the section

src/tests/test_cases/sections.py

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -389,7 +389,6 @@ def test_missing_docstring_another(skip, verbose): # noqa: D213, D407
389389
@expect("D417: Missing argument descriptions in the docstring "
390390
"(argument(s) y are missing descriptions in "
391391
"'test_missing_numpy_args' docstring)")
392-
@expect("D207: Docstring is under-indented")
393392
def test_missing_numpy_args(_private_arg=0, x=1, y=2): # noqa: D406, D407
394393
"""Toggle the gizmo.
395394
@@ -405,13 +404,19 @@ def test_missing_numpy_args(_private_arg=0, x=1, y=2): # noqa: D406, D407
405404
class TestNumpy: # noqa: D203
406405
"""Test class."""
407406

408-
def test_method(self, test, another_test, _, x=1, y=2, _private_arg=1): # noqa: D213, D407
407+
def test_method(self, test, another_test, z, _, x=1, y=2, _private_arg=1): # noqa: D213, D407
409408
"""Test a valid args section.
410409
410+
Some long string with a \
411+
line continuation.
412+
411413
Parameters
412414
----------
413415
test, another_test
414416
Some parameters without type.
417+
z : some parameter with a very long type description that requires a \
418+
line continuation.
419+
But no further description.
415420
x, y : int
416421
Some integer parameters.
417422

0 commit comments

Comments
 (0)