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
I couldn't reproduce this on 3.7, but I can confirm that 3.6 gives a SystemError with the above code: $ ./python _issue30626.py Traceback (most recent call last): File "_issue30626.py", line 30, in exec("open(__file__)",dct) File "", line 1, in SystemError: <class '_io.TextIOWrapper'> returned NULL without setting an error It's plausible this was fixed as part of the interpreter startup refactoring, so I doubt we're going to able to easily isolate the specific change that fixed it :(
That said: given that we know it *is* fixed somewhere in 3.7, it would likely be useful to check the assumption that the startup refactoring fixed it by going to the last commit before that landed and seeing if the error still occurs.
title: "SystemError: SystemError: <class '_io.TextIOWrapper'> returned NULL without setting an error" from open function -> "SystemError: <class '_io.TextIOWrapper'> returned NULL without setting an error" from open function
messages: + components: + Interpreter Core, Library (Lib), IOtitle: "SystemError: SystemError: <class '_io.TextIOWrapper'> returned NULL without setting an error -> "SystemError: SystemError: <class '_io.TextIOWrapper'> returned NULL without setting an error" from open function