Fix grammar for type alias support (#3949)

Fixes #3948
This commit is contained in:
Jelle Zijlstra 2023-10-16 10:53:38 -07:00 committed by GitHub
parent abe57e3d92
commit 722735d20e
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 11 additions and 1 deletions

View File

@ -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. -->

View File

@ -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)

View File

@ -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))
@ -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))