diff options
author | Petr Viktorin <encukou@gmail.com> | 2022-02-02 15:57:51 (GMT) |
---|---|---|
committer | GitHub <noreply@github.com> | 2022-02-02 15:57:51 (GMT) |
commit | 0ef08530124c5ca13a9394f4ac18bee8e6c66409 (patch) | |
tree | ddb496b55243ef3f207bb6fdc744fe84d517196e /Objects | |
parent | 0d05da1fbf39f32d2c22a1f3702f40f916997b60 (diff) | |
download | cpython-0ef08530124c5ca13a9394f4ac18bee8e6c66409.zip cpython-0ef08530124c5ca13a9394f4ac18bee8e6c66409.tar.gz cpython-0ef08530124c5ca13a9394f4ac18bee8e6c66409.tar.bz2 |
bpo-46433: _PyType_GetModuleByDef: handle static types in MRO (GH-30696)
Automerge-Triggered-By: GH:encukou
Diffstat (limited to 'Objects')
-rw-r--r-- | Objects/typeobject.c | 9 |
1 files changed, 4 insertions, 5 deletions
diff --git a/Objects/typeobject.c b/Objects/typeobject.c index f7e0775..0c893ea 100644 --- a/Objects/typeobject.c +++ b/Objects/typeobject.c @@ -3756,11 +3756,10 @@ _PyType_GetModuleByDef(PyTypeObject *type, struct PyModuleDef *def) Py_ssize_t n = PyTuple_GET_SIZE(mro); for (Py_ssize_t i = 0; i < n; i++) { PyObject *super = PyTuple_GET_ITEM(mro, i); - // _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. - assert(_PyType_HasFeature(type, Py_TPFLAGS_HEAPTYPE)); + if(!_PyType_HasFeature((PyTypeObject *)super, Py_TPFLAGS_HEAPTYPE)) { + // Static types in the MRO need to be skipped + continue; + } PyHeapTypeObject *ht = (PyHeapTypeObject*)super; PyObject *module = ht->ht_module; |