diff options
author | Miss Islington (bot) <31488909+miss-islington@users.noreply.github.com> | 2023-06-07 14:35:12 (GMT) |
---|---|---|
committer | GitHub <noreply@github.com> | 2023-06-07 14:35:12 (GMT) |
commit | d36aa244c860f96564c6a94d568bfb7f6a0251bf (patch) | |
tree | d06e2cb63d6d9146e0833ab1ff050d8df8f62e96 | |
parent | 98ccc2de6b71d62388045f4877ee0d2143227a02 (diff) | |
download | cpython-d36aa244c860f96564c6a94d568bfb7f6a0251bf.zip cpython-d36aa244c860f96564c6a94d568bfb7f6a0251bf.tar.gz cpython-d36aa244c860f96564c6a94d568bfb7f6a0251bf.tar.bz2 |
[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 <mail@sobolevn.me>
-rw-r--r-- | Lib/test/test_type_aliases.py | 6 | ||||
-rw-r--r-- | 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 c434996..a3067e5 100644 --- a/Lib/test/test_type_aliases.py +++ b/Lib/test/test_type_aliases.py @@ -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""") diff --git a/Lib/test/test_type_params.py b/Lib/test/test_type_params.py index 7b7b612..6475df6 100644 --- a/Lib/test/test_type_params.py +++ b/Lib/test/test_type_params.py @@ -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""") |