diff -r 7050c9fc1f72 Objects/typeobject.c --- a/Objects/typeobject.c Wed May 04 11:28:09 2016 +0300 +++ b/Objects/typeobject.c Wed May 04 18:43:33 2016 +0300 @@ -2537,11 +2537,24 @@ PyObject * /* Look in tp_dict of types in MRO */ mro = type->tp_mro; - /* If mro is NULL, the type is either not yet initialized - by PyType_Ready(), or already cleared by type_clear(). - Either way the safest thing to do is to return NULL. */ - if (mro == NULL) - return NULL; + if (mro == NULL) { + if (PyType_Ready(type) < 0) { + /* It's not ideal to clear the error condition, + but this function is documented as not setting + an exception, and I don't want to change that. + When PyType_Ready() can't proceed, it won't + set the "ready" flag, so future attempts to ready + the same type will call it again -- hopefully + in a context that propagates the exception out. + */ + PyErr_Clear(); + return NULL; + } + mro = type->tp_mro; + if (mro == NULL) { + return NULL; + } + } res = NULL; assert(PyTuple_Check(mro));