parent
24469c9bd1
commit
7e6d3fac19
@ -35,6 +35,8 @@
|
|||||||
- Fix two crashes in preview style involving edge cases with docstrings (#3451)
|
- Fix two crashes in preview style involving edge cases with docstrings (#3451)
|
||||||
- Exclude string type annotations from improved string processing; fix crash when the
|
- Exclude string type annotations from improved string processing; fix crash when the
|
||||||
return type annotation is stringified and spans across multiple lines (#3462)
|
return type annotation is stringified and spans across multiple lines (#3462)
|
||||||
|
- Fix several crashes in preview style with walrus operators used in `with` statements
|
||||||
|
or tuples (#3473)
|
||||||
|
|
||||||
### Configuration
|
### Configuration
|
||||||
|
|
||||||
|
@ -46,6 +46,7 @@
|
|||||||
is_rpar_token,
|
is_rpar_token,
|
||||||
is_stub_body,
|
is_stub_body,
|
||||||
is_stub_suite,
|
is_stub_suite,
|
||||||
|
is_tuple_containing_walrus,
|
||||||
is_vararg,
|
is_vararg,
|
||||||
is_walrus_assignment,
|
is_walrus_assignment,
|
||||||
is_yield,
|
is_yield,
|
||||||
@ -1279,6 +1280,7 @@ def maybe_make_parens_invisible_in_atom(
|
|||||||
not remove_brackets_around_comma
|
not remove_brackets_around_comma
|
||||||
and max_delimiter_priority_in_atom(node) >= COMMA_PRIORITY
|
and max_delimiter_priority_in_atom(node) >= COMMA_PRIORITY
|
||||||
)
|
)
|
||||||
|
or is_tuple_containing_walrus(node)
|
||||||
):
|
):
|
||||||
return False
|
return False
|
||||||
|
|
||||||
@ -1290,9 +1292,11 @@ def maybe_make_parens_invisible_in_atom(
|
|||||||
syms.return_stmt,
|
syms.return_stmt,
|
||||||
syms.except_clause,
|
syms.except_clause,
|
||||||
syms.funcdef,
|
syms.funcdef,
|
||||||
|
syms.with_stmt,
|
||||||
# these ones aren't useful to end users, but they do please fuzzers
|
# these ones aren't useful to end users, but they do please fuzzers
|
||||||
syms.for_stmt,
|
syms.for_stmt,
|
||||||
syms.del_stmt,
|
syms.del_stmt,
|
||||||
|
syms.for_stmt,
|
||||||
]:
|
]:
|
||||||
return False
|
return False
|
||||||
|
|
||||||
|
@ -563,6 +563,17 @@ def is_one_tuple(node: LN) -> bool:
|
|||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
|
def is_tuple_containing_walrus(node: LN) -> bool:
|
||||||
|
"""Return True if `node` holds a tuple that contains a walrus operator."""
|
||||||
|
if node.type != syms.atom:
|
||||||
|
return False
|
||||||
|
gexp = unwrap_singleton_parenthesis(node)
|
||||||
|
if gexp is None or gexp.type != syms.testlist_gexp:
|
||||||
|
return False
|
||||||
|
|
||||||
|
return any(child.type == syms.namedexpr_test for child in gexp.children)
|
||||||
|
|
||||||
|
|
||||||
def is_one_sequence_between(
|
def is_one_sequence_between(
|
||||||
opening: Leaf,
|
opening: Leaf,
|
||||||
closing: Leaf,
|
closing: Leaf,
|
||||||
|
@ -19,3 +19,7 @@
|
|||||||
@(please := stop)
|
@(please := stop)
|
||||||
def sigh():
|
def sigh():
|
||||||
pass
|
pass
|
||||||
|
|
||||||
|
|
||||||
|
for (x := 3, y := 4) in y:
|
||||||
|
pass
|
||||||
|
@ -49,6 +49,26 @@ def a():
|
|||||||
def this_is_so_dumb() -> (please := no):
|
def this_is_so_dumb() -> (please := no):
|
||||||
pass
|
pass
|
||||||
|
|
||||||
|
async def await_the_walrus():
|
||||||
|
with (x := y):
|
||||||
|
pass
|
||||||
|
|
||||||
|
with (x := y) as z, (a := b) as c:
|
||||||
|
pass
|
||||||
|
|
||||||
|
with (x := await y):
|
||||||
|
pass
|
||||||
|
|
||||||
|
with (x := await a, y := await b):
|
||||||
|
pass
|
||||||
|
|
||||||
|
# Ideally we should remove one set of parentheses
|
||||||
|
with ((x := await a, y := await b)):
|
||||||
|
pass
|
||||||
|
|
||||||
|
with (x := await a), (y := await b):
|
||||||
|
pass
|
||||||
|
|
||||||
|
|
||||||
# output
|
# output
|
||||||
if foo := 0:
|
if foo := 0:
|
||||||
@ -103,3 +123,23 @@ def a():
|
|||||||
def this_is_so_dumb() -> (please := no):
|
def this_is_so_dumb() -> (please := no):
|
||||||
pass
|
pass
|
||||||
|
|
||||||
|
|
||||||
|
async def await_the_walrus():
|
||||||
|
with (x := y):
|
||||||
|
pass
|
||||||
|
|
||||||
|
with (x := y) as z, (a := b) as c:
|
||||||
|
pass
|
||||||
|
|
||||||
|
with (x := await y):
|
||||||
|
pass
|
||||||
|
|
||||||
|
with (x := await a, y := await b):
|
||||||
|
pass
|
||||||
|
|
||||||
|
# Ideally we should remove one set of parentheses
|
||||||
|
with ((x := await a, y := await b)):
|
||||||
|
pass
|
||||||
|
|
||||||
|
with (x := await a), (y := await b):
|
||||||
|
pass
|
||||||
|
Loading…
Reference in New Issue
Block a user