[issue14285] Traceback wrong on ImportError while executing a package
Martin Panter
report at bugs.python.org
Fri Dec 4 19:13:13 EST 2015
Martin Panter added the comment:
I think the problem with doing a blind import of the parent package is it would be hard to differentiate between the ImportError when the package (or an ancestor) is missing, versus a user-generated ImportError. Maybe you could inspect the exception as a workaround (untested):
try:
__import__(pkg_name)
except ImportError as err:
if err.name != pkg_name and not pkg_name.startswith(err.name + "."):
raise
raise error(format(err))
----------
_______________________________________
Python tracker <report at bugs.python.org>
<http://bugs.python.org/issue14285>
_______________________________________
More information about the Python-bugs-list
mailing list