Skip to content

Commit 6144c46

Browse files
Fix parsing of walrus operator in complex with statements (#4630)
1 parent dd278cb commit 6144c46

File tree

3 files changed

+8
-0
lines changed

3 files changed

+8
-0
lines changed

CHANGES.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,8 @@
1010

1111
<!-- Changes that affect Black's stable style -->
1212
- Fix crash while formatting a long `del` statement containing tuples (#4628)
13+
- Fix crash while formatting expressions using the walrus operator in complex
14+
`with` statements (#4630)
1315

1416
### Preview style
1517

src/black/linegen.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1649,6 +1649,7 @@ def maybe_make_parens_invisible_in_atom(
16491649
syms.except_clause,
16501650
syms.funcdef,
16511651
syms.with_stmt,
1652+
syms.testlist_gexp,
16521653
syms.tname,
16531654
# these ones aren't useful to end users, but they do please fuzzers
16541655
syms.for_stmt,

tests/data/cases/pep_572_py310.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,3 +14,8 @@
1414
f((a := b + c for c in range(10)), x)
1515
f(y=(a := b + c for c in range(10)))
1616
f(x, (a := b + c for c in range(10)), y=z, **q)
17+
18+
19+
# Don't remove parens when assignment expr is one of the exprs in a with statement
20+
with x, (a := b):
21+
pass

0 commit comments

Comments
 (0)