Fix parser for TypeVar bounds (#4602)
This commit is contained in:
parent
45cbe572ee
commit
5ae38dd370
@ -26,6 +26,9 @@
|
|||||||
|
|
||||||
<!-- Changes to the parser or to version autodetection -->
|
<!-- Changes to the parser or to version autodetection -->
|
||||||
|
|
||||||
|
- Fix bug where certain unusual expressions (e.g., lambdas) were not accepted
|
||||||
|
in type parameter bounds and defaults. (#4602)
|
||||||
|
|
||||||
### Performance
|
### Performance
|
||||||
|
|
||||||
<!-- Changes that improve Black's performance. -->
|
<!-- Changes that improve Black's performance. -->
|
||||||
|
@ -12,9 +12,9 @@ file_input: (NEWLINE | stmt)* ENDMARKER
|
|||||||
single_input: NEWLINE | simple_stmt | compound_stmt NEWLINE
|
single_input: NEWLINE | simple_stmt | compound_stmt NEWLINE
|
||||||
eval_input: testlist NEWLINE* ENDMARKER
|
eval_input: testlist NEWLINE* ENDMARKER
|
||||||
|
|
||||||
typevar: NAME [':' expr] ['=' expr]
|
typevar: NAME [':' test] ['=' test]
|
||||||
paramspec: '**' NAME ['=' expr]
|
paramspec: '**' NAME ['=' test]
|
||||||
typevartuple: '*' NAME ['=' (expr|star_expr)]
|
typevartuple: '*' NAME ['=' (test|star_expr)]
|
||||||
typeparam: typevar | paramspec | typevartuple
|
typeparam: typevar | paramspec | typevartuple
|
||||||
typeparams: '[' typeparam (',' typeparam)* [','] ']'
|
typeparams: '[' typeparam (',' typeparam)* [','] ']'
|
||||||
|
|
||||||
|
@ -20,6 +20,8 @@ def trailing_comma1[T=int,](a: str):
|
|||||||
def trailing_comma2[T=int](a: str,):
|
def trailing_comma2[T=int](a: str,):
|
||||||
pass
|
pass
|
||||||
|
|
||||||
|
def weird_syntax[T=lambda: 42, **P=lambda: 43, *Ts=lambda: 44](): pass
|
||||||
|
|
||||||
# output
|
# output
|
||||||
|
|
||||||
type A[T = int] = float
|
type A[T = int] = float
|
||||||
@ -61,3 +63,7 @@ def trailing_comma2[T = int](
|
|||||||
a: str,
|
a: str,
|
||||||
):
|
):
|
||||||
pass
|
pass
|
||||||
|
|
||||||
|
|
||||||
|
def weird_syntax[T = lambda: 42, **P = lambda: 43, *Ts = lambda: 44]():
|
||||||
|
pass
|
||||||
|
@ -13,6 +13,8 @@ def it_gets_worse[WhatIsTheLongestTypeVarNameYouCanThinkOfEnoughToMakeBlackSplit
|
|||||||
|
|
||||||
def magic[Trailing, Comma,](): pass
|
def magic[Trailing, Comma,](): pass
|
||||||
|
|
||||||
|
def weird_syntax[T: lambda: 42, U: a or b](): pass
|
||||||
|
|
||||||
# output
|
# output
|
||||||
|
|
||||||
|
|
||||||
@ -56,3 +58,7 @@ def magic[
|
|||||||
Comma,
|
Comma,
|
||||||
]():
|
]():
|
||||||
pass
|
pass
|
||||||
|
|
||||||
|
|
||||||
|
def weird_syntax[T: lambda: 42, U: a or b]():
|
||||||
|
pass
|
||||||
|
Loading…
Reference in New Issue
Block a user