Skip to content

Commit

Permalink
Fix grammar for type alias support (#3949)
Browse files Browse the repository at this point in the history
Fixes #3948
  • Loading branch information
JelleZijlstra committed Oct 16, 2023
1 parent abe57e3 commit 722735d
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 1 deletion.
3 changes: 3 additions & 0 deletions CHANGES.md
Expand Up @@ -37,6 +37,9 @@

<!-- Changes to the parser or to version autodetection -->

- Add support for PEP 695 type aliases containing lambdas and other unusual expressions
(#3949)

### Performance

<!-- Changes that improve Black's performance. -->
Expand Down
2 changes: 1 addition & 1 deletion src/blib2to3/Grammar.txt
Expand Up @@ -108,7 +108,7 @@ dotted_as_names: dotted_as_name (',' dotted_as_name)*
dotted_name: NAME ('.' NAME)*
global_stmt: ('global' | 'nonlocal') NAME (',' NAME)*
assert_stmt: 'assert' test [',' test]
type_stmt: "type" NAME [typeparams] '=' expr
type_stmt: "type" NAME [typeparams] '=' test

compound_stmt: if_stmt | while_stmt | for_stmt | try_stmt | with_stmt | funcdef | classdef | decorated | async_stmt | match_stmt
async_stmt: ASYNC (funcdef | with_stmt | for_stmt)
Expand Down
7 changes: 7 additions & 0 deletions tests/data/cases/type_aliases.py
@@ -1,6 +1,10 @@
# flags: --minimum-version=3.12

type A=int
type Gen[T]=list[T]
type Alias[T]=lambda: T
type And[T]=T and T
type IfElse[T]=T if T else T

type = aliased
print(type(42))
Expand All @@ -9,6 +13,9 @@

type A = int
type Gen[T] = list[T]
type Alias[T] = lambda: T
type And[T] = T and T
type IfElse[T] = T if T else T

type = aliased
print(type(42))

0 comments on commit 722735d

Please sign in to comment.