[3.12] gh-105437: Improve tests of type params names for PEP 695 (GH-105438) (#105452)

(cherry picked from commit 76883af6bf)

Co-authored-by: Nikita Sobolev <mail@sobolevn.me>
This commit is contained in:
Miss Islington (bot) 2023-06-07 07:35:12 -07:00 committed by GitHub
parent 98ccc2de6b
commit d36aa244c8
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 12 additions and 4 deletions

View 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""")

View 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""")