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

5.1.0 regression: D208 (docstring is over-indented) false positive for raw docstring with backslash #502

Open
The-Compiler opened this issue Aug 24, 2020 · 2 comments

Comments

@The-Compiler
Copy link
Member

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 / b0f7d62 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
The-Compiler added a commit to qutebrowser/qutebrowser that referenced this issue Aug 24, 2020
@anntzer
Copy link
Contributor

anntzer commented Sep 17, 2020

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?

@The-Compiler
Copy link
Member Author

That indeed seems to fix the issue, and doesn't introduce any new regressions at least when I run pydocstyle against my project. 👍

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants