[issue14285] Traceback wrong on ImportError while executing a package
Martin Panter
report at bugs.python.org
Thu Dec 3 21:16:14 EST 2015
Martin Panter added the comment:
Even with my committed fix, tracebacks triggered by initializing a parent package are still suppressed:
$ ./python -m hello
Traceback (most recent call last):
File "/media/disk/home/proj/python/cpython/Lib/runpy.py", line 158, in _run_module_as_main
mod_name, mod_spec, code = _get_module_details(mod_name, _Error)
File "/media/disk/home/proj/python/cpython/Lib/runpy.py", line 116, in _get_module_details
__import__(mod_name) # Do not catch exceptions initializing package
File "/media/disk/home/proj/python/cpython/hello/__init__.py", line 1, in <module>
import random; random.dsgjdgj
AttributeError: module 'random' has no attribute 'dsgjdgj'
[Exit 1]
$ ./python -m hello.submodule
/media/disk/home/proj/python/cpython/python: Error while finding spec for 'hello.submodule' (<class 'AttributeError'>: module 'random' has no attribute 'dsgjdgj')
[Exit 1]
Fixing this in general might require a loop around the find_spec() call as in init-ancestor.patch. But I’m unsure if it is worth the extra complication.
----------
Added file: http://bugs.python.org/file41231/init-ancestor.patch
_______________________________________
Python tracker <report at bugs.python.org>
<http://bugs.python.org/issue14285>
_______________________________________
More information about the Python-bugs-list
mailing list