fix: Don't allow unparenthesizing walruses (#4155)

Signed-off-by: RedGuy12 <61329810+RedGuy12@users.noreply.github.com>
Signed-off-by: RedGuy12 <paul@reid-family.org>
This commit is contained in:
cobalt 2024-01-17 13:04:15 -06:00 committed by GitHub
parent b7c3a9fedd
commit 9a331d606f
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
3 changed files with 13 additions and 1 deletions

View File

@ -22,6 +22,7 @@
- Address a missing case in the change to allow empty lines at the beginning of all - Address a missing case in the change to allow empty lines at the beginning of all
blocks, except immediately before a docstring (#4130) blocks, except immediately before a docstring (#4130)
- For stubs, fix logic to enforce empty line after nested classes with bodies (#4141) - For stubs, fix logic to enforce empty line after nested classes with bodies (#4141)
- Fix crash when using a walrus in a dictionary (#4155)
### Configuration ### Configuration

View File

@ -242,7 +242,11 @@ def visit_dictsetmaker(self, node: Node) -> Iterator[Line]:
if i == 0: if i == 0:
continue continue
if node.children[i - 1].type == token.COLON: if node.children[i - 1].type == token.COLON:
if child.type == syms.atom and child.children[0].type == token.LPAR: if (
child.type == syms.atom
and child.children[0].type == token.LPAR
and not is_walrus_assignment(child)
):
if maybe_make_parens_invisible_in_atom( if maybe_make_parens_invisible_in_atom(
child, child,
parent=node, parent=node,

View File

@ -0,0 +1,7 @@
# flags: --preview
{
"is_update": (up := commit.hash in update_hashes)
}
# output
{"is_update": (up := commit.hash in update_hashes)}