Skip to content

Keep the parentheses of a walrus dict value wrapped in redundant parentheses (preview) - #5727

Merged
cobaltt7 merged 2 commits into
psf:mainfrom
sohailshk:fix/dict-value-walrus
Nov 25, 2026
Merged

cobaltt7 merged 2 commits into
psf:mainfrom
sohailshk:fix/dict-value-walrus

Conversation

@sohailshk

Copy link
Copy Markdown
Contributor

Description

With --preview, wrap_long_dict_values_in_parens hides the outer parentheses of ((a := 1)) and then also the inner ones, because the walrus check only sees a single level. {1: ((a := 1))} is formatted to {1: a := 1} and Black fails with INTERNAL ERROR: Black produced invalid code. A walrus dict value always needs its parentheses, so dictsetmaker is added to the parents for which maybe_make_parens_invisible_in_atom keeps a walrus's parentheses.

Checklist - did you ...

  • Implement any code style changes under the --preview style, following the stability policy?
  • Add an entry in CHANGES.md if necessary?
  • Add / update tests if necessary?
  • Add new / update outdated documentation?

The implementation and tests were written with AI assistance.

…ntheses

{1: ((a := 1))} was formatted to {1: a := 1}, which is invalid, under wrap_long_dict_values_in_parens.
@github-actions

github-actions Bot commented Nov 25, 2026 •

Copy link
Copy Markdown
Contributor

diff-shades results comparing this PR (44bde7e) to main (a12e959):

--preview style: no changes

--stable style: no changes


What is this? | Workflow run | diff-shades documentation

@cobaltt7
cobaltt7 merged commit 1e4ab75 into psf:main Nov 25, 2026
59 of 61 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants