From c8277442a5c72a8e5f4f4937f3e291776e3f7b90 Mon Sep 17 00:00:00 2001 From: Tushar Sadhwani Date: Fri, 21 Mar 2025 00:34:21 +0530 Subject: [PATCH 1/4] Fix parsing of walrus operator in complex with statements --- src/black/linegen.py | 1 + tests/data/cases/pep_572_py310.py | 5 +++++ 2 files changed, 6 insertions(+) diff --git a/src/black/linegen.py b/src/black/linegen.py index ee65a7a6e40..1ee9f6a6be6 100644 --- a/src/black/linegen.py +++ b/src/black/linegen.py @@ -1649,6 +1649,7 @@ def maybe_make_parens_invisible_in_atom( syms.except_clause, syms.funcdef, syms.with_stmt, + syms.testlist_gexp, syms.tname, # these ones aren't useful to end users, but they do please fuzzers syms.for_stmt, diff --git a/tests/data/cases/pep_572_py310.py b/tests/data/cases/pep_572_py310.py index ba488d4741c..f79024931f4 100644 --- a/tests/data/cases/pep_572_py310.py +++ b/tests/data/cases/pep_572_py310.py @@ -14,3 +14,8 @@ f((a := b + c for c in range(10)), x) f(y=(a := b + c for c in range(10))) f(x, (a := b + c for c in range(10)), y=z, **q) + + +# Don't remove parens when assignment expr is one of the exprs in a with statement +with x, (a := b): + pass From 3dd407cea7e62aeb27c442526db7fa2d0593a284 Mon Sep 17 00:00:00 2001 From: Tushar Sadhwani Date: Fri, 21 Mar 2025 00:36:36 +0530 Subject: [PATCH 2/4] add changelog --- CHANGES.md | 1 + 1 file changed, 1 insertion(+) diff --git a/CHANGES.md b/CHANGES.md index 05c0011ad94..0bbc83ef2bb 100644 --- a/CHANGES.md +++ b/CHANGES.md @@ -10,6 +10,7 @@ - Fix crash while formatting a long `del` statement containing tuples (#4628) +- Fix crash while formatting names expressions in complex `with` statements (#4630) ### Preview style From 1c90361be66bb5509de030b114e4429628d1af2c Mon Sep 17 00:00:00 2001 From: Tushar Sadhwani Date: Fri, 21 Mar 2025 00:46:12 +0530 Subject: [PATCH 3/4] fix naming in changelog --- CHANGES.md | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/CHANGES.md b/CHANGES.md index 0bbc83ef2bb..a472f968895 100644 --- a/CHANGES.md +++ b/CHANGES.md @@ -10,7 +10,8 @@ - Fix crash while formatting a long `del` statement containing tuples (#4628) -- Fix crash while formatting names expressions in complex `with` statements (#4630) +- Fix crash while formatting expressions with walrus operator in complex `with` + statements (#4630) ### Preview style From 229c48f89fe50be10d882daf6456021e14dcaae7 Mon Sep 17 00:00:00 2001 From: Tushar Sadhwani Date: Fri, 21 Mar 2025 00:46:54 +0530 Subject: [PATCH 4/4] grammar --- CHANGES.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/CHANGES.md b/CHANGES.md index a472f968895..4cbc3d8bd95 100644 --- a/CHANGES.md +++ b/CHANGES.md @@ -10,8 +10,8 @@ - Fix crash while formatting a long `del` statement containing tuples (#4628) -- Fix crash while formatting expressions with walrus operator in complex `with` - statements (#4630) +- Fix crash while formatting expressions using the walrus operator in complex + `with` statements (#4630) ### Preview style