Thanks to visit codestin.com Credit goes to github.com
We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
There was an error while loading. Please reload this page.
1 parent 666b68e commit d93b4acCopy full SHA for d93b4ac
4 files changed
Lib/test/test_typing.py
@@ -4091,6 +4091,22 @@ class C(Generic[T]): pass
4091
with self.assertRaises(TypeError):
4092
C[()]
4093
4094
+ def test_generic_subclass_checks(self):
4095
+ for typ in [list[int], List[int],
4096
+ tuple[int, str], Tuple[int, str],
4097
+ typing.Callable[..., None],
4098
+ collections.abc.Callable[..., None]]:
4099
+ with self.subTest(typ=typ):
4100
+ self.assertRaises(TypeError, issubclass, typ, object)
4101
+ self.assertRaises(TypeError, issubclass, typ, type)
4102
+ self.assertRaises(TypeError, issubclass, typ, typ)
4103
+ self.assertRaises(TypeError, issubclass, object, typ)
4104
+
4105
+ # isinstance is fine:
4106
+ self.assertTrue(isinstance(typ, object))
4107
+ # but, not when the right arg is also a generic:
4108
+ self.assertRaises(TypeError, isinstance, typ, typ)
4109
4110
def test_init(self):
4111
T = TypeVar('T')
4112
S = TypeVar('S')
Misc/NEWS.d/next/Library/2023-04-08-12-43-52.gh-issue-101162.yOCd_J.rst
@@ -0,0 +1,2 @@
1
+Forbid using :func:`builtins.issubclass` with :class:`types.GenericAlias` as
2
+the first argument.
Objects/abstract.c
@@ -2812,7 +2812,7 @@ object_issubclass(PyThreadState *tstate, PyObject *derived, PyObject *cls)
2812
return -1;
2813
}
2814
2815
- /* Probably never reached anymore. */
+ /* Can be reached when infinite recursion happens. */
2816
return recursive_issubclass(derived, cls);
2817
2818
Objects/genericaliasobject.c
@@ -626,6 +626,7 @@ ga_vectorcall(PyObject *self, PyObject *const *args,
626
627
static const char* const attr_exceptions[] = {
628
"__class__",
629
+ "__bases__",
630
"__origin__",
631
"__args__",
632
"__unpacked__",
0 commit comments