mirror of
https://github.com/python/cpython.git
synced 2025-09-27 02:39:58 +00:00
[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:
parent
98ccc2de6b
commit
d36aa244c8
2 changed files with 12 additions and 4 deletions
|
@ -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""")
|
||||
|
|
|
@ -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""")
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue