This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

Author ppperry
Recipients brett.cannon, eric.snow, ncoghlan, ppperry
Date 2017-07-08.02:29:22
SpamBayes Score -1.0
Marked as misclassified Yes
Message-id <1499480964.67.0.223894670164.issue30873@psf.upfronthosting.co.za>
In-reply-to
Content
The following rather long code, reduced from the same example as issue30626, produces a SystemError:

import builtins
from importlib.machinery import PathFinder
import importlib
import sys
import _imp
from functools import partial
def copy_module(module):
    new = type(sys)(module.__name__)
    new.__dict__.update(module.__dict__)
    return new
_absent = object()
def new_exec(code, globals=_absent, locals=_absent, *, new_builtins):
    if globals == _absent:
        frame = sys._getframe(2)
        globals = frame.f_globals
        locals = frame.f_locals
    elif locals == _absent:
        locals = globals
    globals.setdefault("__builtins__", new_builtins);
    return exec(code, globals, locals)
dct={}
dct["__builtins__"] = b = copy_module(builtins)
b.exec = partial(new_exec, new_builtins=b)
spec = PathFinder.find_spec("_bootstrap",importlib.__path__)
source_bootstrap = type(sys)("_bootstrap");
spec.loader.exec_module(source_bootstrap);
external_spec = PathFinder.find_spec("_bootstrap_external",importlib.__path__)
source_bootstrap_external = type(sys)("_bootstrap_external");
external_spec.loader.exec_module(source_bootstrap_external);
source_bootstrap.__name__ = "importlib._bootstrap";
source_bootstrap_external.__name__ = "importlib._bootstrap_external";
new_sys = copy_module(sys)
new_sys.path_importer_cache = {}
new_sys.path_hooks = []
new_sys.meta_path = []
new_sys.modules = {
                    "importlib._bootstrap":source_bootstrap,
                    "importlib._bootstrap_external":source_bootstrap_external,
                  }
for mod in new_sys.modules.values():
    mod.__builtins__ = b
b.__import__ = source_bootstrap.__import__
source_bootstrap._install(new_sys,_imp)
exec("import _pickle", dct)
History
Date User Action Args
2017-07-08 02:29:24ppperrysetrecipients: + ppperry, brett.cannon, ncoghlan, eric.snow
2017-07-08 02:29:24ppperrysetmessageid: <1499480964.67.0.223894670164.issue30873@psf.upfronthosting.co.za>
2017-07-08 02:29:24ppperrylinkissue30873 messages
2017-07-08 02:29:22ppperrycreate