[issue15623] Init time relative imports no longer work from __init__.so modules

Brett Cannon report at bugs.python.org
Fri Aug 17 21:51:22 CEST 2012


Brett Cannon added the comment:

So I can't reproduce under 3.2. First off, building the example code in test.tgz fails thanks to __Py_ZeroStruct not being found (this is with using both an installed Python 3.2 and a checkout build).

Second, when I just make audioop a package in Python 3.2 it still grabs the __init__.py file, so I can't reproduce that way either.

Third, I hand-traced the import code starting in load_module() in Python 3.2 and if you follow::

  import.c:load_module() ->
  importdl.c:_PyImport_GetDynLoadFunc() ->
  import.c:_PyImport_FixupExtensionUnicode()

you will find where a new module gets set in sys.modules (through PyImport_GetModuleDict()) and it's after the PyInit function for the extension module is called. So if there is some magical path that is deep in import.c that is setting the module in sys.modules when there is a __init__.py next to an __init__.so I will need someone who has actually made this work with an empty __init__.py figure out how it's all happening since _PyImport_GetDynLoadFunc() would short-circuit if the module was already in sys.modules and entirely skip executing the PyInit for the extension module.

Fourth, if you go with the work-around, Stefan, just make sure that on error anywhere in your PyInit you remove the module from sys.modules that you injected.

Because of all of this I am making this pending as "won't fix". If someone can figure out what is happening in Python 3.2 I will leave it open until we decide how to handle this, else I will close this before rc1.

----------
resolution:  -> wont fix
status: open -> pending

_______________________________________
Python tracker <report at bugs.python.org>
<http://bugs.python.org/issue15623>
_______________________________________


More information about the Python-bugs-list mailing list