pydocstyle
pydocstyle copied to clipboard
5.1.0 regression: D208 (docstring is over-indented) false positive for raw docstring with backslash
I have a docstring with an ASCII-tree-drawing like this:
"""Module docstring."""
def test_one_level():
r"""Test get_child_frames with one level of children.
o parent
/ \
child1 o o child2
"""
pass
Since pydocstyle 5.1.0, I get:
foo.py:4 in public function `test_one_level`:
D208: Docstring is over-indented
According to git bisect, #472 / b0f7d6235939684af3ae4412cebd5aea02a46c5f is causing this - cc @anntzer
Given that this is marked as a raw string (r"""..."""), I don't think this should be interpreted as a line continuation - Python doesn't do so either:
>>> print(r"""Hello.
...
... World \
... test
... """)
Hello.
World \
test
From a quick try I think
diff --git i/src/pydocstyle/checker.py w/src/pydocstyle/checker.py
index 41e3f35..2ec3e9d 100644
--- i/src/pydocstyle/checker.py
+++ w/src/pydocstyle/checker.py
@@ -332,10 +332,12 @@ class ConventionChecker:
"""
if docstring:
indent = self._get_docstring_indent(definition, docstring)
+ is_raw = docstring.startswith('r')
lines = docstring.split('\n')
if len(lines) > 1:
- # First line and line continuations need no indent.
- lines = [
+ # First line and (for non-raw strings) line continuations need
+ # no indent.
+ lines = lines[1:] if is_raw else [
line
for i, line in enumerate(lines)
if i and not lines[i - 1].endswith('\\')
should fix the problem?
That indeed seems to fix the issue, and doesn't introduce any new regressions at least when I run pydocstyle against my project. :+1: