parent
45c98cf150
commit
c7da3482c7
@ -6006,13 +6006,14 @@ def _stringify_ast(
|
|||||||
|
|
||||||
else:
|
else:
|
||||||
# Constant strings may be indented across newlines, if they are
|
# 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 (
|
if (
|
||||||
isinstance(node, ast.Constant)
|
isinstance(node, ast.Constant)
|
||||||
and field == "value"
|
and field == "value"
|
||||||
and isinstance(value, str)
|
and isinstance(value, str)
|
||||||
):
|
):
|
||||||
normalized = re.sub(r"\n[ \t]+", "\n ", value)
|
normalized = re.sub(r" *\n[ \t]+", "\n ", value).strip()
|
||||||
else:
|
else:
|
||||||
normalized = value
|
normalized = value
|
||||||
yield f"{' ' * (depth+2)}{normalized!r}, # {value.__class__.__name__}"
|
yield f"{' ' * (depth+2)}{normalized!r}, # {value.__class__.__name__}"
|
||||||
|
@ -1,5 +1,5 @@
|
|||||||
class MyClass:
|
class MyClass:
|
||||||
"""Multiline
|
""" Multiline
|
||||||
class docstring
|
class docstring
|
||||||
"""
|
"""
|
||||||
|
|
||||||
@ -11,7 +11,7 @@ def method(self):
|
|||||||
|
|
||||||
|
|
||||||
def foo():
|
def foo():
|
||||||
"""This is a docstring with
|
"""This is a docstring with
|
||||||
some lines of text here
|
some lines of text here
|
||||||
"""
|
"""
|
||||||
return
|
return
|
||||||
@ -66,6 +66,13 @@ def over_indent():
|
|||||||
"""
|
"""
|
||||||
pass
|
pass
|
||||||
|
|
||||||
|
|
||||||
|
def single_line():
|
||||||
|
"""But with a newline after it!
|
||||||
|
|
||||||
|
"""
|
||||||
|
pass
|
||||||
|
|
||||||
# output
|
# output
|
||||||
|
|
||||||
class MyClass:
|
class MyClass:
|
||||||
@ -136,3 +143,8 @@ def over_indent():
|
|||||||
- And the closing quote is too deep
|
- And the closing quote is too deep
|
||||||
"""
|
"""
|
||||||
pass
|
pass
|
||||||
|
|
||||||
|
|
||||||
|
def single_line():
|
||||||
|
"""But with a newline after it!"""
|
||||||
|
pass
|
||||||
|
Loading…
Reference in New Issue
Block a user