Add support for named exprs inside function calls as gen-exps (#3327)
This commit is contained in:
parent
b60b85b234
commit
1c786ee627
@ -26,6 +26,10 @@
|
|||||||
|
|
||||||
<!-- Changes to the parser or to version autodetection -->
|
<!-- Changes to the parser or to version autodetection -->
|
||||||
|
|
||||||
|
- Parsing support has been added for walruses inside generator expression that are
|
||||||
|
passed as function args (for example,
|
||||||
|
`any(match := my_re.match(text) for text in texts)`) (#3327).
|
||||||
|
|
||||||
### Performance
|
### Performance
|
||||||
|
|
||||||
<!-- Changes that improve Black's performance. -->
|
<!-- Changes that improve Black's performance. -->
|
||||||
|
@ -186,7 +186,7 @@ arglist: argument (',' argument)* [',']
|
|||||||
# multiple (test comp_for) arguments are blocked; keyword unpackings
|
# multiple (test comp_for) arguments are blocked; keyword unpackings
|
||||||
# that precede iterable unpackings are blocked; etc.
|
# that precede iterable unpackings are blocked; etc.
|
||||||
argument: ( test [comp_for] |
|
argument: ( test [comp_for] |
|
||||||
test ':=' test |
|
test ':=' test [comp_for] |
|
||||||
test 'as' test |
|
test 'as' test |
|
||||||
test '=' asexpr_test |
|
test '=' asexpr_test |
|
||||||
'**' test |
|
'**' test |
|
||||||
|
@ -2,3 +2,14 @@
|
|||||||
x[a:=0]
|
x[a:=0]
|
||||||
x[a:=0, b:=1]
|
x[a:=0, b:=1]
|
||||||
x[5, b:=0]
|
x[5, b:=0]
|
||||||
|
|
||||||
|
# Walruses are allowed inside generator expressions on function calls since 3.10.
|
||||||
|
if any(match := pattern_error.match(s) for s in buffer):
|
||||||
|
if match.group(2) == data_not_available:
|
||||||
|
# Error OK to ignore.
|
||||||
|
pass
|
||||||
|
|
||||||
|
f(a := b + c for c in range(10))
|
||||||
|
f((a := b + c for c in range(10)), x)
|
||||||
|
f(y=(a := b + c for c in range(10)))
|
||||||
|
f(x, (a := b + c for c in range(10)), y=z, **q)
|
||||||
|
Loading…
Reference in New Issue
Block a user