Unverified Commit c7da3482 authored by Jelle Zijlstra's avatar Jelle Zijlstra Committed by GitHub
Browse files

fix crashes on docstring whitespace changes (#1417)

Fixes #1415
parent 45c98cf1
Loading
Loading
Loading
Loading
+3 −2
Changes for src/black/__init__.py: 3 added lines, 2 removed lines.
Original line number Diff line number Diff line
@@ -6006,13 +6006,14 @@ def _stringify_ast(

        else:
            # Constant strings may be indented across newlines, if they are
            # docstrings; fold spaces after newlines when comparing
            # docstrings; fold spaces after newlines when comparing. Similarly,
            # trailing and leading space may be removed.
            if (
                isinstance(node, ast.Constant)
                and field == "value"
                and isinstance(value, str)
            ):
                normalized = re.sub(r"\n[ \t]+", "\n ", value)
                normalized = re.sub(r" *\n[ \t]+", "\n ", value).strip()
            else:
                normalized = value
            yield f"{'  ' * (depth+2)}{normalized!r},  # {value.__class__.__name__}"
+12 −0
Changes for tests/data/docstring.py: 12 added lines, 0 removed lines.
Original line number Diff line number Diff line
@@ -66,6 +66,13 @@ def over_indent():
    """
  pass


def single_line():
    """But with a newline after it!

    """
    pass

# output

class MyClass:
@@ -136,3 +143,8 @@ def over_indent():
      - And the closing quote is too deep
    """
    pass


def single_line():
    """But with a newline after it!"""
    pass