Don't fold postscriptum standalone comment into last statement

This happened when the last statement was a simple statement.

Fixes #18
Fixes #28
This commit is contained in:
Łukasz Langa 2018-03-17 00:54:30 -07:00
parent 6c3ce53b60
commit 68c71b621f
3 changed files with 12 additions and 1 deletions

View File

@ -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 * if top level functions were separated by a comment, don't put four
empty lines after the upper function 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 missing space in numpy-style array indexing (#33)
* fixed spurious space after star-based unary expressions (#31) * fixed spurious space after star-based unary expressions (#31)

View File

@ -1115,7 +1115,7 @@ def generate_comments(leaf: Leaf) -> Iterator[Leaf]:
if content and (content[0] not in {' ', '!', '#'}): if content and (content[0] not in {' ', '!', '#'}):
content = ' ' + content content = ' ' + content
is_standalone_comment = ( 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: if not is_standalone_comment:
# simple trailing comment # simple trailing comment

View File

@ -124,6 +124,9 @@ async def f():
signal.getsignal(signal.SIGINT) != signal.default_int_handler signal.getsignal(signal.SIGINT) != signal.default_int_handler
): ):
return True return True
last_call()
# standalone comment at ENDMARKER
# output # output
@ -275,3 +278,6 @@ async def f():
or signal.getsignal(signal.SIGINT) != signal.default_int_handler or signal.getsignal(signal.SIGINT) != signal.default_int_handler
): ):
return True return True
last_call()
# standalone comment at ENDMARKER