From 68eb5c9797681fe77482dbe8ca5fa6a0c6af3b86 Mon Sep 17 00:00:00 2001 From: Jelle Zijlstra Date: Mon, 16 Oct 2023 06:38:16 -0700 Subject: [PATCH 1/2] Fix grammar for type alias support Fixes #3948 --- CHANGES.md | 3 +++ src/blib2to3/Grammar.txt | 2 +- tests/data/cases/type_aliases.py | 7 +++++++ 3 files changed, 11 insertions(+), 1 deletion(-) diff --git a/CHANGES.md b/CHANGES.md index a608551815f..3675356413d 100644 --- a/CHANGES.md +++ b/CHANGES.md @@ -35,6 +35,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 be91df75740..5db78723cec 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 a3c1931c9fc..9631bfd5ccc 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 @@ 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)) From 7bb21e90953347c479860bd7fff679e1c304a482 Mon Sep 17 00:00:00 2001 From: "pre-commit-ci[bot]" <66853113+pre-commit-ci[bot]@users.noreply.github.com> Date: Mon, 16 Oct 2023 13:41:30 +0000 Subject: [PATCH 2/2] [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci --- CHANGES.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/CHANGES.md b/CHANGES.md index 3675356413d..a141c4cf9c5 100644 --- a/CHANGES.md +++ b/CHANGES.md @@ -35,8 +35,8 @@ -- Add support for PEP 695 type aliases containing lambdas and other unusual - expressions (#3949) +- Add support for PEP 695 type aliases containing lambdas and other unusual expressions + (#3949) ### Performance