Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix grammar for type alias support #3949

Merged
merged 2 commits into from Oct 16, 2023
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.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
3 changes: 3 additions & 0 deletions CHANGES.md
Expand Up @@ -35,6 +35,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))