File tree Expand file tree Collapse file tree 3 files changed +47
-1
lines changed Expand file tree Collapse file tree 3 files changed +47
-1
lines changed Original file line number Diff line number Diff line change 10
10
11
11
<!-- Changes that affect Black's stable style -->
12
12
13
+ - Fix an infinite loop when using ` # fmt: on/off ` in the middle of an expression or code
14
+ block (#3158 )
13
15
- Fix incorrect handling of ` # fmt: skip ` on colon ` : ` lines. (#3148 )
14
16
- Comments are no longer deleted when a line had spaces removed around power operators
15
17
(#2874 )
Original file line number Diff line number Diff line change 13
13
from blib2to3 .pgen2 import token
14
14
15
15
from black .nodes import first_leaf_column , preceding_leaf , container_of
16
- from black .nodes import STANDALONE_COMMENT , WHITESPACE
16
+ from black .nodes import CLOSING_BRACKETS , STANDALONE_COMMENT , WHITESPACE
17
17
18
18
# types
19
19
LN = Union [Leaf , Node ]
@@ -227,6 +227,14 @@ def generate_ignored_nodes(
227
227
# fix for fmt: on in children
228
228
if contains_fmt_on_at_column (container , leaf .column , preview = preview ):
229
229
for child in container .children :
230
+ if isinstance (child , Leaf ) and is_fmt_on (child , preview = preview ):
231
+ if child .type in CLOSING_BRACKETS :
232
+ # This means `# fmt: on` is placed at a different bracket level
233
+ # than `# fmt: off`. This is an invalid use, but as a courtesy,
234
+ # we include this closing bracket in the ignored nodes.
235
+ # The alternative is to fail the formatting.
236
+ yield child
237
+ return
230
238
if contains_fmt_on_at_column (child , leaf .column , preview = preview ):
231
239
return
232
240
yield child
Original file line number Diff line number Diff line change
1
+ # Regression test for https://github.com/psf/black/issues/3129.
2
+ setup (
3
+ entry_points = {
4
+ # fmt: off
5
+ "console_scripts" : [
6
+ "foo-bar"
7
+ "=foo.bar.:main" ,
8
+ # fmt: on
9
+ ] # Includes an formatted indentation.
10
+ },
11
+ )
12
+
13
+
14
+ # Regression test for https://github.com/psf/black/issues/2015.
15
+ run (
16
+ # fmt: off
17
+ [
18
+ "ls" ,
19
+ "-la" ,
20
+ ]
21
+ # fmt: on
22
+ + path ,
23
+ check = True ,
24
+ )
25
+
26
+
27
+ # Regression test for https://github.com/psf/black/issues/3026.
28
+ def test_func ():
29
+ # yapf: disable
30
+ if unformatted ( args ):
31
+ return True
32
+ # yapf: enable
33
+ elif b :
34
+ return True
35
+
36
+ return False
You can’t perform that action at this time.
0 commit comments