summaryrefslogtreecommitdiffstats
path: root/Lib/test/test_typing.py
diff options
context:
space:
mode:
authorSerhiy Storchaka <storchaka@gmail.com>2022-04-13 03:08:49 (GMT)
committerGitHub <noreply@github.com>2022-04-13 03:08:49 (GMT)
commit15537c51c188a6633248c25d211d5216e673aee3 (patch)
tree6ccc7404181320732cd6c02377d0fc8041b00a0e /Lib/test/test_typing.py
parent0859368335d470b9ff33fc53ed9a85ec2654b278 (diff)
downloadcpython-15537c51c188a6633248c25d211d5216e673aee3.zip
cpython-15537c51c188a6633248c25d211d5216e673aee3.tar.gz
cpython-15537c51c188a6633248c25d211d5216e673aee3.tar.bz2
bpo-43224: Forbid TypeVar substitution with Unpack (GH-32031)
Diffstat (limited to 'Lib/test/test_typing.py')
-rw-r--r--Lib/test/test_typing.py14
1 files changed, 14 insertions, 0 deletions
diff --git a/Lib/test/test_typing.py b/Lib/test/test_typing.py
index 2afa544..97fc66a 100644
--- a/Lib/test/test_typing.py
+++ b/Lib/test/test_typing.py
@@ -562,6 +562,20 @@ class TypeVarTupleTests(BaseTestCase):
self.assertEqual(E[float, str, int, bytes],
Tuple[List[float], A[str, int], List[bytes]])
+ def test_bad_var_substitution(self):
+ Ts = TypeVarTuple('Ts')
+ T = TypeVar('T')
+ T2 = TypeVar('T2')
+ class G(Generic[Unpack[Ts]]): pass
+
+ for A in G, Tuple:
+ B = A[T, Unpack[Ts], str, T2]
+ with self.assertRaises(TypeError):
+ B[int, Unpack[Ts]]
+ C = A[T, Unpack[Ts], str, T2]
+ with self.assertRaises(TypeError):
+ C[int, Unpack[Ts], Unpack[Ts]]
+
def test_repr_is_correct(self):
Ts = TypeVarTuple('Ts')
self.assertEqual(repr(Ts), 'Ts')