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 scoder
Recipients Dormouse759, ncoghlan, petr.viktorin, scoder, terry.reedy
Date 2017-07-22.15:34:51
SpamBayes Score -1.0
Marked as misclassified Yes
Message-id <1500737692.33.0.64209653701.issue30403@psf.upfronthosting.co.za>
In-reply-to
Content
FYI, I've finally managed to find the time for implementing PEP 489 style module initialisation in Cython. It was so easy that I'm sorry it took me so long to get started. Cython 0.26 is fresh out, so the feature should go into 0.27.
https://github.com/cython/cython/pull/1794

Note that I ended up implementing the Py_mod_create function which is now copying attributes from the spec right after creation. While not strictly required, I guess, it turned out to be easiest, but it seems like this does now conflict with the current "-m" implementation. I asked on the github commit why that restriction exists.

One thing I stumbled over: exec_in_module() is a Python level function. Would that make it possible to re-execute an already imported module? That could be dangerous, because C level module code often initialises resources that a simple re-execution of the module exec function would overwrite without cleaning up the old state. I did not (yet?) implement support for m_clear() etc., and that might actually turn out to be really risky when it comes to supporting arbitrary user code.

OTOH, that case is easy to detect because the module is already completely initialised at that point.

As far as I understand it, all that this PEP really changes from the POV of the extension module is that it calls the exec function with a different module name ("__main__"). Cython already provides that feature itself (by embedding CPython in a C main function), so this should be easy to support.
History
Date User Action Args
2017-07-22 15:34:52scodersetrecipients: + scoder, terry.reedy, ncoghlan, petr.viktorin, Dormouse759
2017-07-22 15:34:52scodersetmessageid: <1500737692.33.0.64209653701.issue30403@psf.upfronthosting.co.za>
2017-07-22 15:34:52scoderlinkissue30403 messages
2017-07-22 15:34:51scodercreate