Skip to content
This repository was archived by the owner on Nov 19, 2021. It is now read-only.

Commit e94a41f

Browse files
committed
Look at actual parenthesis when generating ignored leafs.
Fixes psf#385
1 parent df965b0 commit e94a41f

File tree

3 files changed

+74
-13
lines changed

3 files changed

+74
-13
lines changed

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -823,6 +823,7 @@ More details can be found in [CONTRIBUTING](CONTRIBUTING.md).
823823
### 18.8b0
824824

825825
* fix parsing of `__future__` imports with renames (#389)
826+
* fix scope of `# fmt: off` when directly preceding `yield` and other nodes (#385)
826827

827828
### 18.6b4
828829

black.py

Lines changed: 1 addition & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -797,18 +797,6 @@ def show(cls, code: Union[str, Leaf, Node]) -> None:
797797
syms.testlist_gexp,
798798
syms.testlist_star_expr,
799799
}
800-
SURROUNDED_BY_BRACKETS = {
801-
syms.typedargslist,
802-
syms.arglist,
803-
syms.subscriptlist,
804-
syms.vfplist,
805-
syms.import_as_names,
806-
syms.yield_expr,
807-
syms.testlist_gexp,
808-
syms.testlist_star_expr,
809-
syms.listmaker,
810-
syms.dictsetmaker,
811-
}
812800
TEST_DESCENDANTS = {
813801
syms.test,
814802
syms.lambdef,
@@ -1853,7 +1841,7 @@ def container_of(leaf: Leaf) -> LN:
18531841
if parent.type == syms.file_input:
18541842
break
18551843

1856-
if parent.type in SURROUNDED_BY_BRACKETS:
1844+
if parent.prev_sibling is not None and parent.prev_sibling.type in BRACKETS:
18571845
break
18581846

18591847
container = parent

tests/data/fmtonoff.py

Lines changed: 72 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,39 @@ def spaces2(result= _core.Value(None)):
4848
# fmt: off
4949
key: 'value',
5050
}
51+
52+
def subscriptlist():
53+
atom[
54+
# fmt: off
55+
'some big and',
56+
'complex subscript',
57+
# fmt: on
58+
goes + here, andhere,
59+
]
60+
61+
def import_as_names():
62+
# fmt: off
63+
from hello import a, b
64+
'unformatted'
65+
# fmt: on
66+
67+
def testlist_star_expr():
68+
# fmt: off
69+
a , b = *hello
70+
'unformatted'
71+
# fmt: on
72+
73+
def yield_expr():
74+
# fmt: off
75+
yield hello
76+
'unformatted'
77+
# fmt: on
78+
'formatted'
79+
# fmt: off
80+
( yield hello )
81+
'unformatted'
82+
# fmt: on
83+
5184
def example(session):
5285
# fmt: off
5386
result = session\
@@ -142,6 +175,7 @@ def single_literal_yapf_disable():
142175
xxxxxxxxxx_xxxxxxxxxxx_xxxxxxx_xxxxxxxxx=5
143176
)
144177
# fmt: off
178+
yield 'hello'
145179
# No formatting to the end of the file
146180
l=[1,2,3]
147181
d={'a':1,
@@ -219,6 +253,43 @@ def spaces2(result=_core.Value(None)):
219253
}
220254

221255

256+
def subscriptlist():
257+
atom[
258+
# fmt: off
259+
'some big and',
260+
'complex subscript',
261+
# fmt: on
262+
goes + here,
263+
andhere,
264+
]
265+
266+
267+
def import_as_names():
268+
# fmt: off
269+
from hello import a, b
270+
'unformatted'
271+
# fmt: on
272+
273+
274+
def testlist_star_expr():
275+
# fmt: off
276+
a , b = *hello
277+
'unformatted'
278+
# fmt: on
279+
280+
281+
def yield_expr():
282+
# fmt: off
283+
yield hello
284+
'unformatted'
285+
# fmt: on
286+
"formatted"
287+
# fmt: off
288+
( yield hello )
289+
'unformatted'
290+
# fmt: on
291+
292+
222293
def example(session):
223294
# fmt: off
224295
result = session\
@@ -327,6 +398,7 @@ def single_literal_yapf_disable():
327398
xxxxxxxxxx_xxxxxxxxxxx_xxxxxxx_xxxxxxxxx=5,
328399
)
329400
# fmt: off
401+
yield 'hello'
330402
# No formatting to the end of the file
331403
l=[1,2,3]
332404
d={'a':1,

0 commit comments

Comments
 (0)