summaryrefslogtreecommitdiffstats
path: root/Lib/test/test_typing.py
diff options
context:
space:
mode:
authorNikita Sobolev <mail@sobolevn.me>2023-08-11 19:12:11 (GMT)
committerGitHub <noreply@github.com>2023-08-11 19:12:11 (GMT)
commitd93b4ac2ff7bce07fb1c8805f43838818598191c (patch)
treeed96f4cf84526f069de3cdedc0cd07365a981836 /Lib/test/test_typing.py
parent666b68e8f252e3c6238d6eed1fc82937a774316f (diff)
downloadcpython-d93b4ac2ff7bce07fb1c8805f43838818598191c.zip
cpython-d93b4ac2ff7bce07fb1c8805f43838818598191c.tar.gz
cpython-d93b4ac2ff7bce07fb1c8805f43838818598191c.tar.bz2
gh-101162: Forbid using issubclass() with GenericAlias as the 1st arg (GH-103369)
Diffstat (limited to 'Lib/test/test_typing.py')
-rw-r--r--Lib/test/test_typing.py16
1 files changed, 16 insertions, 0 deletions
diff --git a/Lib/test/test_typing.py b/Lib/test/test_typing.py
index 0450a87..fa39c79 100644
--- a/Lib/test/test_typing.py
+++ b/Lib/test/test_typing.py
@@ -4091,6 +4091,22 @@ class GenericTests(BaseTestCase):
with self.assertRaises(TypeError):
C[()]
+ def test_generic_subclass_checks(self):
+ for typ in [list[int], List[int],
+ tuple[int, str], Tuple[int, str],
+ typing.Callable[..., None],
+ collections.abc.Callable[..., None]]:
+ with self.subTest(typ=typ):
+ self.assertRaises(TypeError, issubclass, typ, object)
+ self.assertRaises(TypeError, issubclass, typ, type)
+ self.assertRaises(TypeError, issubclass, typ, typ)
+ self.assertRaises(TypeError, issubclass, object, typ)
+
+ # isinstance is fine:
+ self.assertTrue(isinstance(typ, object))
+ # but, not when the right arg is also a generic:
+ self.assertRaises(TypeError, isinstance, typ, typ)
+
def test_init(self):
T = TypeVar('T')
S = TypeVar('S')