From 91de9ea6e3a83fe29c165814271a9bffdd5e6097 Mon Sep 17 00:00:00 2001 From: =?utf8?q?=C5=81ukasz=20Langa?= Date: Mon, 21 May 2018 12:29:36 -0700 Subject: [PATCH] Fix invalid code in an omitted trailer on large expressions Fixes #237 --- README.md | 6 +++++- black.py | 3 +++ tests/composition.py | 8 ++++++++ 3 files changed, 16 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index f3a9bb8..7038d96 100644 --- a/README.md +++ b/README.md @@ -654,7 +654,11 @@ More details can be found in [CONTRIBUTING](CONTRIBUTING.md). ### 18.5b1 (unreleased) * Python grammar pickle caches are stored with the formatting caches, making - *Black* work in environments where site-packages is not user-writable (#192). + *Black* work in environments where site-packages is not user-writable (#192) + +* fixed invalid code produced when standalone comments were present in a trailer + that was omitted from line splitting on a large expression (#237) + ### 18.5b0 diff --git a/black.py b/black.py index 46c64a3..8d55164 100644 --- a/black.py +++ b/black.py @@ -2606,6 +2606,9 @@ def generate_trailers_to_omit(line: Line, line_length: int) -> Iterator[Set[Leaf if length > line_length: break + if leaf.type == STANDALONE_COMMENT: + break + optional_brackets.discard(id(leaf)) if opening_bracket: if leaf is opening_bracket: diff --git a/tests/composition.py b/tests/composition.py index 71eee6a..f8cd5ed 100644 --- a/tests/composition.py +++ b/tests/composition.py @@ -32,6 +32,14 @@ class C: # Another ): print(i) + xxxxxxxxxxxxxxxx = Yyyy2YyyyyYyyyyy( + push_manager=context.request.resource_manager, + max_items_to_push=num_items, + batch_size=Yyyy2YyyyYyyyyYyyy.FULL_SIZE, + ).push( + # Only send the first n items. + items=items[:num_items] + ) return ( "Utterly failed doctest test for %s\n" ' File "%s", line %s, in %s\n\n%s' -- 2.39.5