From 5e1f620af7ff5d2bb4205e398849e5395999a0cb Mon Sep 17 00:00:00 2001 From: Jelle Zijlstra Date: Thu, 13 Aug 2020 16:40:45 -0700 Subject: [PATCH] fix some docstring crashes (#1593) Allow removing some trailing whitespace --- src/black/__init__.py | 2 +- tests/data/docstring.py | 18 +++++++++++++++++- 2 files changed, 18 insertions(+), 2 deletions(-) diff --git a/src/black/__init__.py b/src/black/__init__.py index 349da1e..36c0394 100644 --- a/src/black/__init__.py +++ b/src/black/__init__.py @@ -6063,7 +6063,7 @@ def _stringify_ast( and field == "value" and isinstance(value, str) ): - normalized = re.sub(r" *\n[ \t]+", "\n ", value).strip() + normalized = re.sub(r" *\n[ \t]*", "\n", value).strip() else: normalized = value yield f"{' ' * (depth+2)}{normalized!r}, # {value.__class__.__name__}" diff --git a/tests/data/docstring.py b/tests/data/docstring.py index f5adeb7..fcb8eb1 100644 --- a/tests/data/docstring.py +++ b/tests/data/docstring.py @@ -46,7 +46,7 @@ def zort(): def poit(): """ - Lorem ipsum dolor sit amet. + Lorem ipsum dolor sit amet. Consectetur adipiscing elit: - sed do eiusmod tempor incididunt ut labore @@ -58,6 +58,14 @@ def poit(): pass +def under_indent(): + """ + These lines are indented in a way that does not +make sense. + """ + pass + + def over_indent(): """ This has a shallow indent @@ -136,6 +144,14 @@ def poit(): pass +def under_indent(): + """ + These lines are indented in a way that does not + make sense. + """ + pass + + def over_indent(): """ This has a shallow indent -- 2.39.2