This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

Author ncoghlan
Recipients Dormouse759, ncoghlan, pablogsal, petr.viktorin, shihai1991, vstinner
Date 2020-03-07.12:22:22
SpamBayes Score -1.0
Marked as misclassified Yes
Message-id <1583583742.59.0.11361543648.issue39824@roundup.psfhosted.org>
In-reply-to
Content
One of the intended use cases for Py_mod_create is to return instances of ModuleType subclasses rather than straight ModuleType instances. And those are definitely legal to define:

>>> import __main__
>>> class MyModule(type(__main__)): pass
... 
>>> m = MyModule('example')
>>> m
<module 'example'>

So it isn't valid to skip calling the cleanup functions just because md_state is NULL - we have no idea what Py_mod_create might have done that needs to be cleaned up.

It would *probably* be legitimate to skip calling the cleanup functions when there's no Py_mod_create slot defined, but then the rules for "Do I need to account for md_state potentially being NULL or not?" are getting complicated enough that the safest option for a module author is to always assume that md_state might be NULL and handle that case appropriately.
History
Date User Action Args
2020-03-07 12:22:22ncoghlansetrecipients: + ncoghlan, vstinner, petr.viktorin, Dormouse759, pablogsal, shihai1991
2020-03-07 12:22:22ncoghlansetmessageid: <1583583742.59.0.11361543648.issue39824@roundup.psfhosted.org>
2020-03-07 12:22:22ncoghlanlinkissue39824 messages
2020-03-07 12:22:22ncoghlancreate