STINNER Victor <vstin...@python.org> added the comment:
Oh, it seems like I misunderstood type_ready_mro() change. The check is only done on static types type. The MRO of heap types is not checked. -- In my change, I wrote: // _PyType_GetModuleByDef() must only be called on a heap type created // by PyType_FromModuleAndSpec() or on its subclasses. // type_ready_mro() ensures that a static type cannot inherit from a // heap type. based on this function: static int type_ready_mro(PyTypeObject *type) { /* Calculate method resolution order */ if (mro_internal(type, NULL) < 0) { return -1; } assert(type->tp_mro != NULL); assert(PyTuple_Check(type->tp_mro)); /* All bases of statically allocated type should be statically allocated */ if (!(type->tp_flags & Py_TPFLAGS_HEAPTYPE)) { PyObject *mro = type->tp_mro; Py_ssize_t n = PyTuple_GET_SIZE(mro); for (Py_ssize_t i = 0; i < n; i++) { PyTypeObject *base = (PyTypeObject *)PyTuple_GET_ITEM(mro, i); if (PyType_Check(base) && (base->tp_flags & Py_TPFLAGS_HEAPTYPE)) { PyErr_Format(PyExc_TypeError, "type '%.100s' is not dynamically allocated but " "its base type '%.100s' is dynamically allocated", type->tp_name, base->tp_name); return -1; } } } return 0; } This code comes from bpo-22079: commit e09bcc874a21ce351a7fe73b9a137e236550d03c Author: Serhiy Storchaka <storch...@gmail.com> Date: Wed Jan 28 11:03:33 2015 +0200 Issue #22079: PyType_Ready() now checks that statically allocated type has no dynamically allocated bases. Rationale: https://bugs.python.org/issue22079#msg236830 -- Note: PyType_Ready() function was very big and complex. I splitted this huge function into sub-functions in bpo-43770. I hope that it's a little bit more readable yet. I tried but failed to find a bug about tp_getattro and tp_setattro inheritance ---------- _______________________________________ Python tracker <rep...@bugs.python.org> <https://bugs.python.org/issue46433> _______________________________________ _______________________________________________ Python-bugs-list mailing list Unsubscribe: https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com