diff options
author | Serhiy Storchaka <storchaka@gmail.com> | 2022-11-01 09:33:09 +0200 |
---|---|---|
committer | GitHub <noreply@github.com> | 2022-11-01 09:33:09 +0200 |
commit | 0e15c31c7e9907fdbe38a3f419b669fed5bb3b33 (patch) | |
tree | 14a32e4a22f2b236624cbbb21a278e3bffc8bad3 /Lib/test/test_typing.py | |
parent | f5afb7f2331efa8f64080576a75517c3a96442b9 (diff) | |
download | cpython-0e15c31c7e9907fdbe38a3f419b669fed5bb3b33.tar.gz cpython-0e15c31c7e9907fdbe38a3f419b669fed5bb3b33.zip |
gh-98852: Fix subscription of type aliases (GH-98920)
Fix subscription of type aliases containing bare generic types or types
like TypeVar: for example tuple[A, T][int] and tuple[TypeVar, T][int],
where A is a generic type, and T is a type variable.
Diffstat (limited to 'Lib/test/test_typing.py')
-rw-r--r-- | Lib/test/test_typing.py | 28 |
1 files changed, 28 insertions, 0 deletions
diff --git a/Lib/test/test_typing.py b/Lib/test/test_typing.py index 9571d952903..f8168bd19f4 100644 --- a/Lib/test/test_typing.py +++ b/Lib/test/test_typing.py @@ -3916,6 +3916,34 @@ class GenericTests(BaseTestCase): # C version of GenericAlias self.assertEqual(list[A()].__parameters__, (T,)) + def test_non_generic_subscript(self): + T = TypeVar('T') + class G(Generic[T]): + pass + class A: + __parameters__ = (T,) + + for s in (int, G, A, List, list, + TypeVar, TypeVarTuple, ParamSpec, + types.GenericAlias, types.UnionType): + + for t in Tuple, tuple: + with self.subTest(tuple=t, sub=s): + self.assertEqual(t[s, T][int], t[s, int]) + self.assertEqual(t[T, s][int], t[int, s]) + a = t[s] + with self.assertRaises(TypeError): + a[int] + + for c in Callable, collections.abc.Callable: + with self.subTest(callable=c, sub=s): + self.assertEqual(c[[s], T][int], c[[s], int]) + self.assertEqual(c[[T], s][int], c[[int], s]) + a = c[[s], s] + with self.assertRaises(TypeError): + a[int] + + class ClassVarTests(BaseTestCase): def test_basics(self): |