From b250aed47bf11240b460bf4ecb57ba3f28078fd1 Mon Sep 17 00:00:00 2001 From: =?utf8?q?=C5=81ukasz=20Langa?= Date: Tue, 24 Apr 2018 12:40:46 -0700 Subject: [PATCH] Do not enforce empty lines after control flow statements Fixes #90 --- README.md | 8 ++++---- black.py | 10 ---------- tests/expression.diff | 18 ++++-------------- tests/expression.py | 8 -------- tests/function.py | 2 -- 5 files changed, 8 insertions(+), 38 deletions(-) diff --git a/README.md b/README.md index 4663176..a589d0d 100644 --- a/README.md +++ b/README.md @@ -218,10 +218,7 @@ bother you if you overdo it by a few km/h". *Black* avoids spurious vertical whitespace. This is in the spirit of PEP 8 which says that in-function vertical whitespace should only be -used sparingly. One exception is control flow statements: *Black* will -always emit an extra empty line after ``return``, ``raise``, ``break``, -``continue``, and ``yield``. This is to make changes in control flow -more prominent to readers of your code. +used sparingly. *Black* will allow single empty lines inside functions, and single and double empty lines on module level left by the original editors, except @@ -528,6 +525,9 @@ More details can be found in [CONTRIBUTING](CONTRIBUTING.md). * generalized star expression handling, including double stars; this fixes multiplication making expressions "unsafe" for trailing commas (#132) +* Black no longer enforces putting empty lines behind control flow statements + (#90) + * fixed comment indentation when a standalone comment closes a block (#16, #32) * fixed standalone comments receiving extra empty lines if immediately preceding diff --git a/black.py b/black.py index 5bf466a..95489f3 100644 --- a/black.py +++ b/black.py @@ -1056,9 +1056,6 @@ class EmptyLineTracker: newlines -= 1 return newlines, 0 - if current_line.is_flow_control: - return before, 1 - if ( self.previous_line and self.previous_line.is_import @@ -1067,13 +1064,6 @@ class EmptyLineTracker: ): return (before or 1), 0 - if ( - self.previous_line - and self.previous_line.is_yield - and (not current_line.is_yield or depth != self.previous_line.depth) - ): - return (before or 1), 0 - return before, 0 diff --git a/tests/expression.diff b/tests/expression.diff index da48a13..11c1355 100644 --- a/tests/expression.diff +++ b/tests/expression.diff @@ -129,7 +129,7 @@ ] slice[0] slice[0:1] -@@ -123,88 +145,122 @@ +@@ -123,88 +145,114 @@ numpy[-(c + 1):, d] numpy[:, l[-2]] numpy[:, ::-1] @@ -190,10 +190,9 @@ + def gen(): yield from outside_of_generator -+ a = (yield) -+ ++ async def f(): await some.complicated[0].call(with_args=(True or (1 is not 1))) -print(* [] or [1]) @@ -242,8 +241,6 @@ -if ( - aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa / - aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa --): -- return True +print(*lambda x: x) +for (x,) in (1,), (2,), (3,): + ... @@ -263,42 +260,35 @@ + or signal.getsignal(signal.SIGINT) != signal.default_int_handler +): + return True -+ +if ( + aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa + | aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa +): + return True -+ +if ( + aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa + & aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa +): + return True -+ +if ( + aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa + + aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa +): + return True -+ +if ( + aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa + - aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa +): + return True -+ +if ( + aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa + * aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa +): + return True -+ +if ( + aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa + / aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa -+): -+ return True -+ + ): + return True last_call() # standalone comment at ENDMARKER diff --git a/tests/expression.py b/tests/expression.py index 2c4d8dd..274c150 100644 --- a/tests/expression.py +++ b/tests/expression.py @@ -409,7 +409,6 @@ mapping = { def gen(): yield from outside_of_generator - a = (yield) @@ -438,42 +437,35 @@ if ( or signal.getsignal(signal.SIGINT) != signal.default_int_handler ): return True - if ( aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa | aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa ): return True - if ( aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa & aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa ): return True - if ( aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa + aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa ): return True - if ( aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa - aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa ): return True - if ( aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa * aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa ): return True - if ( aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa / aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa ): return True - last_call() # standalone comment at ENDMARKER diff --git a/tests/function.py b/tests/function.py index 08f9414..9a12bf6 100644 --- a/tests/function.py +++ b/tests/function.py @@ -102,13 +102,11 @@ def func_no_args(): c if True: raise RuntimeError - if False: ... for i in range(10): print(i) continue - exec("new-style exec", {}, {}) return None -- 2.39.5