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 brett.cannon
Recipients Arfrever, brett.cannon, eric.snow, georg.brandl, meador.inge, scoder
Date 2012-08-13.19:01:12
SpamBayes Score -1.0
Marked as misclassified Yes
Message-id <1344884473.49.0.627698828408.issue15623@psf.upfronthosting.co.za>
In-reply-to
Content
My guess is import.c is noticing the __init__.py, creating the module for the package, and then somehow it cascades into importing __init__.so which essentially does a reload on the module object that is already in sys.modules and thus doesn't cause the parent module check to fail.

The problem with that is those semantics suck as that assumes cascading semantics which would cross the finder/loader barrier. So we can't keep the *exact* semantics in Python 3.3.

But I do see three possible solutions to fixing this. One is testing if having ExtensionFileLoader insert a practically empty module into sys.modules *before* calling imp.load_dynamic(). This would actually be easy to test by using importlib.util.module_for_loader on ExtensionFileLoader.load_module(). This might be a slight change in semantics (and assumes imp.load_dynamic() will do a reload as appropriate instead of blindly creating a new module), but then if anyone is going to notice it will be Cython so if it works in this case and Cython doesn't fail further it is probably safe.

The second option is to tweak the extension module initialization process to make sure the module being initialized is inserted into sys.modules early enough and still cleaned up properly. The question, though, is what is it doing now as the module is not passed in directly into the PyInit function but by PyModule_Create instead and I don't know who handles cleanup of the module if something fails and the PyInit returns NULL.

Third is having Cython tweak itself for 3.3 to just directly inject the module object into sys.modules before it does any relative imports. It's the least graceful solution and puts the onus on Cython for a change in semantics, but I don't see why that would break anything.
History
Date User Action Args
2012-08-13 19:01:13brett.cannonsetrecipients: + brett.cannon, georg.brandl, scoder, Arfrever, meador.inge, eric.snow
2012-08-13 19:01:13brett.cannonsetmessageid: <1344884473.49.0.627698828408.issue15623@psf.upfronthosting.co.za>
2012-08-13 19:01:12brett.cannonlinkissue15623 messages
2012-08-13 19:01:12brett.cannoncreate