| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -4091,6 +4091,22 @@ class C(Generic[T]): pass | |||
| 4091 | 4091 | with self.assertRaises(TypeError): | |
| 4092 | 4092 | C[()] | |
| 4093 | 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 | + | ||
| 4094 | 4110 | def test_init(self): | |
| 4095 | 4111 | T = TypeVar('T') | |
| 4096 | 4112 | S = TypeVar('S') | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -0,0 +1,2 @@ | |||
| 1 | + Forbid using :func:`builtins.issubclass` with :class:`types.GenericAlias` as | ||
| 2 | + the first argument. | ||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -2812,7 +2812,7 @@ object_issubclass(PyThreadState *tstate, PyObject *derived, PyObject *cls) | |||
| 2812 | 2812 | return -1; | |
| 2813 | 2813 | } | |
| 2814 | 2814 | ||
| 2815 | - /* Probably never reached anymore. */ | ||
| 2815 | + /* Can be reached when infinite recursion happens. */ | ||
| 2816 | 2816 | return recursive_issubclass(derived, cls); | |
| 2817 | 2817 | } | |
| 2818 | 2818 | ||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -626,6 +626,7 @@ ga_vectorcall(PyObject *self, PyObject *const *args, | |||
| 626 | 626 | ||
| 627 | 627 | static const char* const attr_exceptions[] = { | |
| 628 | 628 | "__class__", | |
| 629 | + "__bases__", | ||
| 629 | 630 | "__origin__", | |
| 630 | 631 | "__args__", | |
| 631 | 632 | "__unpacked__", | |
| Back | FazBrowse Home | New Git URL |
0 commit comments