[New-bugs-announce] [issue15623] Init time relative imports no longer work from __init__.so modules
Stefan Behnel
report at bugs.python.org
Sat Aug 11 17:02:05 CEST 2012
New submission from Stefan Behnel:
Since CPython 2.5, relative imports could be used from __init__.so package modules. This stopped working in CPython 3.3.
This is a follow-up ticket to issue15576.
This feature is exercised by Cython's initial_file_path test, which now gives this result:
Traceback (most recent call last):
File "<string>", line 1, in <module>
File "__init__.py", line 8, in init my_test_package (my_test_package/__init__.c:1032)
SystemError: Parent module 'my_test_package' not loaded, cannot perform relative import
It is meant to check that Cython provides a fake __path__ for the package module for the init function (as long as issue13429 isn't resolved). With that, relative imports worked before.
The test code is here, failing in line 21 (each section is a separate file), when it tries to do a relative import at the module level, i.e. at module init time.
https://github.com/cython/cython/blob/master/tests/run/initial_file_path.srctree
I'm running the test like this:
python3 runtests.py --no-cpp --no-pyregr --no-unit --debug -vv initial_file_path
I also tried printing sys.modules and the package really isn't registered there yet at the time of the import.
----------
components: Interpreter Core
messages: 167967
nosy: scoder
priority: normal
severity: normal
status: open
title: Init time relative imports no longer work from __init__.so modules
type: behavior
versions: Python 3.3
_______________________________________
Python tracker <report at bugs.python.org>
<http://bugs.python.org/issue15623>
_______________________________________
More information about the New-bugs-announce
mailing list