From: Jelle Zijlstra Date: Mon, 16 Oct 2023 17:53:38 +0000 (-0700) Subject: Fix grammar for type alias support (#3949) X-Git-Url: https://git.madduck.net/etc/vim.git/commitdiff_plain/722735d20ebdc66c0da0e0df7658293455694500?ds=sidebyside;hp=abe57e3d92727f1b26c717fad3978159b987fe79 Fix grammar for type alias support (#3949) Fixes #3948 --- diff --git a/CHANGES.md b/CHANGES.md index 1f6a008..610a9de 100644 --- a/CHANGES.md +++ b/CHANGES.md @@ -37,6 +37,9 @@ +- Add support for PEP 695 type aliases containing lambdas and other unusual expressions + (#3949) + ### Performance diff --git a/src/blib2to3/Grammar.txt b/src/blib2to3/Grammar.txt index be91df7..5db7872 100644 --- a/src/blib2to3/Grammar.txt +++ b/src/blib2to3/Grammar.txt @@ -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) diff --git a/tests/data/cases/type_aliases.py b/tests/data/cases/type_aliases.py index a3c1931..9631bfd 100644 --- a/tests/data/cases/type_aliases.py +++ b/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)) @@ -9,6 +13,9 @@ print(type(42)) 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))