From 68c71b621f5c80c243ba8a177c5a2059b3ace1d9 Mon Sep 17 00:00:00 2001 From: =?utf8?q?=C5=81ukasz=20Langa?= Date: Sat, 17 Mar 2018 00:54:30 -0700 Subject: [PATCH 1/1] Don't fold postscriptum standalone comment into last statement This happened when the last statement was a simple statement. Fixes #18 Fixes #28 --- README.md | 5 +++++ black.py | 2 +- tests/expression.py | 6 ++++++ 3 files changed, 12 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index 0ccef30..38b27e5 100644 --- a/README.md +++ b/README.md @@ -272,6 +272,11 @@ More details can be found in [CONTRIBUTING](CONTRIBUTING.md). * if top level functions were separated by a comment, don't put four empty lines after the upper function +* fixed unstable formatting of newlines with imports + +* fixed unintentional folding of post scriptum standalone comments + into last statement if it was a simple statement (#18, #28) + * fixed missing space in numpy-style array indexing (#33) * fixed spurious space after star-based unary expressions (#31) diff --git a/black.py b/black.py index 89155f6..f305e8d 100644 --- a/black.py +++ b/black.py @@ -1115,7 +1115,7 @@ def generate_comments(leaf: Leaf) -> Iterator[Leaf]: if content and (content[0] not in {' ', '!', '#'}): content = ' ' + content is_standalone_comment = ( - '\n' in before_comment or '\n' in content or leaf.type == token.DEDENT + '\n' in before_comment or '\n' in content or leaf.type == token.ENDMARKER ) if not is_standalone_comment: # simple trailing comment diff --git a/tests/expression.py b/tests/expression.py index 87a03f6..d90b7cf 100644 --- a/tests/expression.py +++ b/tests/expression.py @@ -124,6 +124,9 @@ if ( signal.getsignal(signal.SIGINT) != signal.default_int_handler ): return True +last_call() +# standalone comment at ENDMARKER + # output @@ -275,3 +278,6 @@ if ( or signal.getsignal(signal.SIGINT) != signal.default_int_handler ): return True + +last_call() +# standalone comment at ENDMARKER -- 2.39.5