Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions CHANGES.md
Original file line number Diff line number Diff line change
Expand Up @@ -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. -->
Expand Down
6 changes: 3 additions & 3 deletions src/blib2to3/Grammar.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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)* [','] ']'

Expand Down
6 changes: 6 additions & 0 deletions tests/data/cases/type_param_defaults.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
6 changes: 6 additions & 0 deletions tests/data/cases/type_params.py
Original file line number Diff line number Diff line change
Expand Up @@ -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


Expand Down Expand Up @@ -56,3 +58,7 @@ def magic[
Comma,
]():
pass


def weird_syntax[T: lambda: 42, U: a or b]():
pass
Loading