]> git.ipfire.org Git - thirdparty/Python/cpython.git/commitdiff
[3.12] gh-105437: Improve tests of type params names for PEP 695 (GH-105438) (#105452)
authorMiss Islington (bot) <31488909+miss-islington@users.noreply.github.com>
Wed, 7 Jun 2023 14:35:12 +0000 (07:35 -0700)
committerGitHub <noreply@github.com>
Wed, 7 Jun 2023 14:35:12 +0000 (14:35 +0000)
(cherry picked from commit 76883af6bf28b7e810df172bd6762bf2cb64df08)

Co-authored-by: Nikita Sobolev <mail@sobolevn.me>
Lib/test/test_type_aliases.py
Lib/test/test_type_params.py

index c43499609aaa56dc99cf7b39b64a1c80a4462011..a3067e521e023ef2ade97cc90a6cbdc056b088f1 100644 (file)
@@ -8,8 +8,10 @@ from typing import Callable, TypeAliasType, TypeVar, get_args
 
 
 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""")
index 7b7b6122c028e5e595625c525669e6fc75c6084d..6475df6f5bba434c7e64bb5ebd0e718882ba66fe 100644 (file)
@@ -8,8 +8,14 @@ from typing import Generic, Sequence, TypeVar, TypeVarTuple, ParamSpec, get_args
 
 
 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""")