summaryrefslogtreecommitdiffstats
path: root/Objects/typeobject.c
diff options
context:
space:
mode:
authorSerhiy Storchaka <storchaka@gmail.com>2016-10-08 09:24:09 (GMT)
committerSerhiy Storchaka <storchaka@gmail.com>2016-10-08 09:24:09 (GMT)
commit61dd7ff0735936b77071a90151faccb9eb8ca16d (patch)
tree6fdcf06bd27bcef4130de96e2471323049630965 /Objects/typeobject.c
parent6a35bf6ca051f07edf0044278a1bf71b88111320 (diff)
downloadcpython-61dd7ff0735936b77071a90151faccb9eb8ca16d.zip
cpython-61dd7ff0735936b77071a90151faccb9eb8ca16d.tar.gz
cpython-61dd7ff0735936b77071a90151faccb9eb8ca16d.tar.bz2
Issue #26906: Resolving special methods of uninitialized type now causes
implicit initialization of the type instead of a fail.
Diffstat (limited to 'Objects/typeobject.c')
-rw-r--r--Objects/typeobject.c24
1 files changed, 19 insertions, 5 deletions
diff --git a/Objects/typeobject.c b/Objects/typeobject.c
index f6d4663..932f9e9 100644
--- a/Objects/typeobject.c
+++ b/Objects/typeobject.c
@@ -2545,11 +2545,25 @@ _PyType_Lookup(PyTypeObject *type, PyObject *name)
/* 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 ((type->tp_flags & Py_TPFLAGS_READYING) == 0 &&
+ 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));