Author christian.heimes
Recipients christian.heimes, corona10, petr.viktorin, vstinner
Date 2020-11-20.10:28:13
SpamBayes Score -1.0
Marked as misclassified Yes
Message-id <>
PyType_GetModule() may return wrong or unexpected result when a type has 
the feature flag Py_TPFLAGS_BASETYPE. The base type flag permits subclassing of an extension class. The function will return NULL when a type is subclasses in Python space or a different module object when the type is subclasses and initialized in a differen C extension module.

All subclassable types must use _PyType_GetModuleByDef() to safely access  module and module state struct. It's easy to miss the problem. I missed it when I ported some of my code to heap types and multiphase init.

I propose to either a guard to PyType_GetModule() to prevent misuse of the function or to add a variant of the function that prevents misuse.
Date User Action Args
2020-11-20 10:28:14christian.heimessetrecipients: + christian.heimes, vstinner, petr.viktorin, corona10
2020-11-20 10:28:13christian.heimessetmessageid: <>
2020-11-20 10:28:13christian.heimeslinkissue42418 messages
2020-11-20 10:28:13christian.heimescreate