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:
parent
b7c3a9fedd
commit
9a331d606f
@ -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
|
||||||
|
|
||||||
|
@ -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,
|
||||||
|
7
tests/data/cases/walrus_in_dict.py
Normal file
7
tests/data/cases/walrus_in_dict.py
Normal file
@ -0,0 +1,7 @@
|
|||||||
|
# flags: --preview
|
||||||
|
{
|
||||||
|
"is_update": (up := commit.hash in update_hashes)
|
||||||
|
}
|
||||||
|
|
||||||
|
# output
|
||||||
|
{"is_update": (up := commit.hash in update_hashes)}
|
Loading…
Reference in New Issue
Block a user