File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -10,6 +10,9 @@ Release date: TBA
1010Core and Builtins
1111-----------------
1212
13+ - Issue #26906: Resolving special methods of uninitialized type now causes
14+ implicit initialization of the type instead of a fail.
15+
1316- Issue #18287: PyType_Ready() now checks that tp_name is not NULL.
1417 Original patch by Niklas Koep.
1518
Original file line number Diff line number Diff line change @@ -2869,11 +2869,25 @@ _PyType_Lookup(PyTypeObject *type, PyObject *name)
28692869 /* Look in tp_dict of types in MRO */
28702870 mro = type -> tp_mro ;
28712871
2872- /* If mro is NULL, the type is either not yet initialized
2873- by PyType_Ready(), or already cleared by type_clear().
2874- Either way the safest thing to do is to return NULL. */
2875- if (mro == NULL )
2876- return NULL ;
2872+ if (mro == NULL ) {
2873+ if ((type -> tp_flags & Py_TPFLAGS_READYING ) == 0 &&
2874+ PyType_Ready (type ) < 0 ) {
2875+ /* It's not ideal to clear the error condition,
2876+ but this function is documented as not setting
2877+ an exception, and I don't want to change that.
2878+ When PyType_Ready() can't proceed, it won't
2879+ set the "ready" flag, so future attempts to ready
2880+ the same type will call it again -- hopefully
2881+ in a context that propagates the exception out.
2882+ */
2883+ PyErr_Clear ();
2884+ return NULL ;
2885+ }
2886+ mro = type -> tp_mro ;
2887+ if (mro == NULL ) {
2888+ return NULL ;
2889+ }
2890+ }
28772891
28782892 res = NULL ;
28792893 /* keep a strong reference to mro because type->tp_mro can be replaced
You can’t perform that action at this time.
0 commit comments