Treat walruses like other binary operators in subscripts (#4109)

Fixes #4078
This commit is contained in:
cobalt 2023-12-28 00:24:25 -06:00 committed by GitHub
parent 51786141cc
commit c80685f361
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 13 additions and 3 deletions

View File

@ -14,6 +14,9 @@
<!-- Changes that affect Black's preview style -->
- Fix bug where spaces were not added around parenthesized walruses in subscripts,
unlike other binary operators (#4109)
### Configuration
<!-- Changes to how Black can be configured -->

View File

@ -446,8 +446,15 @@ def is_complex_subscript(self, leaf: Leaf) -> bool:
if subscript_start.type == syms.subscriptlist:
subscript_start = child_towards(subscript_start, leaf)
# When this is moved out of preview, add syms.namedexpr_test directly to
# TEST_DESCENDANTS in nodes.py
if Preview.walrus_subscript in self.mode:
test_decendants = TEST_DESCENDANTS | {syms.namedexpr_test}
else:
test_decendants = TEST_DESCENDANTS
return subscript_start is not None and any(
n.type in TEST_DESCENDANTS for n in subscript_start.pre_order()
n.type in test_decendants for n in subscript_start.pre_order()
)
def enumerate_with_length(