Nick Coghlan <ncogh...@gmail.com> added the comment:
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. ---------- _______________________________________ Python tracker <rep...@bugs.python.org> <https://bugs.python.org/issue39824> _______________________________________ _______________________________________________ Python-bugs-list mailing list Unsubscribe: https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com