mirror of
https://github.com/python/cpython.git
synced 2025-08-30 05:35:08 +00:00
gh-101162: Forbid using issubclass() with GenericAlias as the 1st arg (GH-103369)
This commit is contained in:
parent
666b68e8f2
commit
d93b4ac2ff
4 changed files with 20 additions and 1 deletions
|
@ -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')
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue