diff options
author | Serhiy Storchaka <storchaka@gmail.com> | 2022-04-13 03:08:49 (GMT) |
---|---|---|
committer | GitHub <noreply@github.com> | 2022-04-13 03:08:49 (GMT) |
commit | 15537c51c188a6633248c25d211d5216e673aee3 (patch) | |
tree | 6ccc7404181320732cd6c02377d0fc8041b00a0e /Lib/test/test_typing.py | |
parent | 0859368335d470b9ff33fc53ed9a85ec2654b278 (diff) | |
download | cpython-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.py | 14 |
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') |