Message295654
This code (reduced from an example I had of trying to debug code including the module-level code of already imported modules), raises a SystemError:
import builtins
from importlib.machinery import PathFinder
from importlib.util import find_spec
import importlib
import sys
import _imp
dct={}
def copy_module(module):
new = type(sys)(module.__name__)
new.__dict__.update(module.__dict__)
return new
dct["__builtins__"] = b = copy_module(builtins)
spec = PathFinder.find_spec("_bootstrap",importlib.__path__)
source_bootstrap = type(sys)("_bootstrap");
spec.loader.exec_module(source_bootstrap);
source_bootstrap.__name__ = "importlib._bootstrap";
new_sys = copy_module(sys)
new_sys.path_hooks = []
new_sys.meta_path = []
new_sys.modules = {
"importlib._bootstrap":source_bootstrap,
"importlib._bootstrap_external":importlib._bootstrap_external,
}
b.__import__ = source_bootstrap.__import__
source_bootstrap._install(new_sys,_imp)
dct["__file__"]=__file__
exec("open(__file__)",dct)
The actual file passed to the open function doesn't matter, as long as it would work |
|
Date |
User |
Action |
Args |
2017-06-10 18:57:30 | ppperry | set | recipients:
+ ppperry |
2017-06-10 18:57:30 | ppperry | set | messageid: <1497121050.36.0.650813384782.issue30626@psf.upfronthosting.co.za> |
2017-06-10 18:57:30 | ppperry | link | issue30626 messages |
2017-06-10 18:57:29 | ppperry | create | |
|