File tree 3 files changed +33
-3
lines changed
3 files changed +33
-3
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 a crash when a colon line is marked between ` # fmt: off ` and ` # fmt: on ` (#3439 )
14
+
13
15
### Preview style
14
16
15
17
<!-- Changes that affect Black's preview style -->
Original file line number Diff line number Diff line change @@ -232,7 +232,7 @@ def generate_ignored_nodes(
232
232
233
233
# fix for fmt: on in children
234
234
if children_contains_fmt_on (container , preview = preview ):
235
- for child in container .children :
235
+ for index , child in enumerate ( container .children ) :
236
236
if isinstance (child , Leaf ) and is_fmt_on (child , preview = preview ):
237
237
if child .type in CLOSING_BRACKETS :
238
238
# This means `# fmt: on` is placed at a different bracket level
@@ -241,6 +241,16 @@ def generate_ignored_nodes(
241
241
# The alternative is to fail the formatting.
242
242
yield child
243
243
return
244
+ if (
245
+ child .type == token .INDENT
246
+ and index < len (container .children ) - 1
247
+ and children_contains_fmt_on (
248
+ container .children [index + 1 ], preview = preview
249
+ )
250
+ ):
251
+ # This means `# fmt: on` is placed right after an indentation
252
+ # level, and we shouldn't swallow the previous INDENT token.
253
+ return
244
254
if children_contains_fmt_on (child , preview = preview ):
245
255
return
246
256
yield child
Original file line number Diff line number Diff line change @@ -64,7 +64,7 @@ async def call(param):
64
64
print ( "This will be formatted" )
65
65
66
66
67
- # Regression test for https://github.com/psf/black/issues/2985
67
+ # Regression test for https://github.com/psf/black/issues/2985.
68
68
class Named (t .Protocol ):
69
69
# fmt: off
70
70
@property
@@ -75,6 +75,15 @@ def this_will_be_formatted ( self, **kwargs ) -> Named: ...
75
75
# fmt: on
76
76
77
77
78
+ # Regression test for https://github.com/psf/black/issues/3436.
79
+ if x :
80
+ return x
81
+ # fmt: off
82
+ elif unformatted :
83
+ # fmt: on
84
+ will_be_formatted ()
85
+
86
+
78
87
# output
79
88
80
89
@@ -144,7 +153,7 @@ async def call(param):
144
153
print ("This will be formatted" )
145
154
146
155
147
- # Regression test for https://github.com/psf/black/issues/2985
156
+ # Regression test for https://github.com/psf/black/issues/2985.
148
157
class Named (t .Protocol ):
149
158
# fmt: off
150
159
@property
@@ -156,3 +165,12 @@ def this_will_be_formatted(self, **kwargs) -> Named:
156
165
...
157
166
158
167
# fmt: on
168
+
169
+
170
+ # Regression test for https://github.com/psf/black/issues/3436.
171
+ if x :
172
+ return x
173
+ # fmt: off
174
+ elif unformatted :
175
+ # fmt: on
176
+ will_be_formatted ()
You can’t perform that action at this time.
0 commit comments