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