[issue15110] strange Tracebacks with importlib
Amaury Forgeot d'Arc
report at bugs.python.org
Sun Jul 8 15:07:16 CEST 2012
Amaury Forgeot d'Arc <amauryfa at gmail.com> added the comment:
I really like the "_exec_module" trick, but it should be applied to builtin modules as well. I hacked _sre.c and got:
~/python/cpython3.x$ ./python
Traceback (most recent call last):
File "/home/amauryfa/python/cpython3.x/Lib/site.py", line 70, in <module>
import re
File "/home/amauryfa/python/cpython3.x/Lib/re.py", line 122, in <module>
import sre_compile
File "/home/amauryfa/python/cpython3.x/Lib/sre_compile.py", line 13, in <module>
import _sre, sys
File "<frozen importlib._bootstrap>", line 1318, in _find_and_load
File "<frozen importlib._bootstrap>", line 1285, in _find_and_load_unlocked
File "<frozen importlib._bootstrap>", line 347, in set_package_wrapper
File "<frozen importlib._bootstrap>", line 360, in set_loader_wrapper
File "<frozen importlib._bootstrap>", line 443, in _requires_builtin_wrapper
File "<frozen importlib._bootstrap>", line 493, in load_module
ValueError: Just a test
This change correctly hides importlib frames:
diff -r 9afdd8c25bf2 Lib/importlib/_bootstrap.py
--- a/Lib/importlib/_bootstrap.py Sun Jul 08 14:00:06 2012 +0200
+++ b/Lib/importlib/_bootstrap.py Sun Jul 08 15:03:27 2012 +0200
@@ -490,12 +490,15 @@
"""Load a built-in module."""
is_reload = fullname in sys.modules
try:
- return _imp.init_builtin(fullname)
+ return self._exec_module(fullname)
except:
if not is_reload and fullname in sys.modules:
del sys.modules[fullname]
raise
+ def _exec_module(self, fullname):
+ return _imp.init_builtin(fullname)
+
@classmethod
@_requires_builtin
def get_code(cls, fullname):
----------
_______________________________________
Python tracker <report at bugs.python.org>
<http://bugs.python.org/issue15110>
_______________________________________
More information about the Python-bugs-list
mailing list