From d36aa244c860f96564c6a94d568bfb7f6a0251bf Mon Sep 17 00:00:00 2001 From: "Miss Islington (bot)" <31488909+miss-islington@users.noreply.github.com> Date: Wed, 7 Jun 2023 07:35:12 -0700 Subject: [PATCH] [3.12] gh-105437: Improve tests of type params names for PEP 695 (GH-105438) (#105452) (cherry picked from commit 76883af6bf28b7e810df172bd6762bf2cb64df08) Co-authored-by: Nikita Sobolev --- Lib/test/test_type_aliases.py | 6 ++++-- Lib/test/test_type_params.py | 10 ++++++++-- 2 files changed, 12 insertions(+), 4 deletions(-) diff --git a/Lib/test/test_type_aliases.py b/Lib/test/test_type_aliases.py index c43499609aaa56..a3067e521e023e 100644 --- a/Lib/test/test_type_aliases.py +++ b/Lib/test/test_type_aliases.py @@ -8,8 +8,10 @@ class TypeParamsInvalidTest(unittest.TestCase): - def test_name_collision_01(self): - check_syntax_error(self, """type TA1[A, **A] = None""", "duplicate type parameter 'A'") + def test_name_collisions(self): + check_syntax_error(self, 'type TA1[A, **A] = None', "duplicate type parameter 'A'") + check_syntax_error(self, 'type T[A, *A] = None', "duplicate type parameter 'A'") + check_syntax_error(self, 'type T[*A, **A] = None', "duplicate type parameter 'A'") def test_name_non_collision_02(self): ns = run_code("""type TA1[A] = lambda A: A""") diff --git a/Lib/test/test_type_params.py b/Lib/test/test_type_params.py index 7b7b6122c028e5..6475df6f5bba43 100644 --- a/Lib/test/test_type_params.py +++ b/Lib/test/test_type_params.py @@ -8,8 +8,14 @@ class TypeParamsInvalidTest(unittest.TestCase): - def test_name_collision_01(self): - check_syntax_error(self, """def func[**A, A](): ...""") + def test_name_collisions(self): + check_syntax_error(self, 'def func[**A, A](): ...', "duplicate type parameter 'A'") + check_syntax_error(self, 'def func[A, *A](): ...', "duplicate type parameter 'A'") + check_syntax_error(self, 'def func[*A, **A](): ...', "duplicate type parameter 'A'") + + check_syntax_error(self, 'class C[**A, A](): ...', "duplicate type parameter 'A'") + check_syntax_error(self, 'class C[A, *A](): ...', "duplicate type parameter 'A'") + check_syntax_error(self, 'class C[*A, **A](): ...', "duplicate type parameter 'A'") def test_name_non_collision_02(self): ns = run_code("""def func[A](A): return A""")