Author: Amaury Forgeot d'Arc <amaur...@gmail.com> Branch: py35-getbuiltin Changeset: r87461:ecaeac990f09 Date: 2016-09-30 08:02 +0200 http://bitbucket.org/pypy/pypy/changeset/ecaeac990f09/
Log: Progress: space.getbuiltinmodule() does not use or update sys.modules diff --git a/lib-python/3/importlib/_bootstrap.py b/lib-python/3/importlib/_bootstrap.py --- a/lib-python/3/importlib/_bootstrap.py +++ b/lib-python/3/importlib/_bootstrap.py @@ -1137,6 +1137,6 @@ sys.meta_path.append(FrozenImporter) global _bootstrap_external - _frozen_importlib_external = sys.modules['_frozen_importlib_external'] + import _frozen_importlib_external _bootstrap_external = _frozen_importlib_external _frozen_importlib_external._install(sys.modules[__name__]) diff --git a/pypy/interpreter/baseobjspace.py b/pypy/interpreter/baseobjspace.py --- a/pypy/interpreter/baseobjspace.py +++ b/pypy/interpreter/baseobjspace.py @@ -491,14 +491,6 @@ def getbuiltinmodule(self, name, force_init=False, reuse=True): w_name = self.wrap(name) - w_modules = self.sys.get('modules') - if not force_init: - assert reuse - try: - return self.getitem(w_modules, w_name) - except OperationError as e: - if not e.match(self, self.w_KeyError): - raise # If the module is a builtin but not yet imported, # retrieve it and initialize it @@ -509,23 +501,18 @@ "getbuiltinmodule() called with non-builtin module %s", name) - # Add the module to sys.modules and initialize the module. The - # order is important to avoid recursions. from pypy.interpreter.module import Module if isinstance(w_mod, Module): if not reuse and w_mod.startup_called: # create a copy of the module. (see issue1514) eventlet # patcher relies on this behaviour. w_mod2 = self.wrap(Module(self, w_name)) - self.setitem(w_modules, w_name, w_mod2) w_mod.getdict(self) # unlazy w_initialdict self.call_method(w_mod2.getdict(self), 'update', w_mod.w_initialdict) return w_mod2 - self.setitem(w_modules, w_name, w_mod) - w_mod.init(self) - else: - self.setitem(w_modules, w_name, w_mod) + if not w_mod.startup_called or force_init: + w_mod.init(self) return w_mod def get_builtinmodule_to_install(self): @@ -651,10 +638,10 @@ if self.config.objspace.usemodules.cpyext: from pypy.module.cpyext.state import State self.fromcache(State).build_api(self) - self.getbuiltinmodule('sys') - self.getbuiltinmodule('_imp') - self.getbuiltinmodule('_frozen_importlib') - self.getbuiltinmodule('builtins') + w_modules = self.sys.get('modules') + for name in ('sys', '_imp', '_frozen_importlib', 'builtins'): + mod = self.getbuiltinmodule(name) + self.setitem(w_modules, mod.w_name, mod) for mod in self.builtin_modules.values(): mod.setup_after_space_initialization() diff --git a/pypy/module/_frozen_importlib/__init__.py b/pypy/module/_frozen_importlib/__init__.py --- a/pypy/module/_frozen_importlib/__init__.py +++ b/pypy/module/_frozen_importlib/__init__.py @@ -77,6 +77,7 @@ def startup(self, space): """Copy our __import__ to builtins.""" + space.setitem(space.sys.get('modules'), self.w_name, self) w_install = self.getdictvalue(space, '_install') space.call_function(w_install, space.getbuiltinmodule('sys'), diff --git a/pypy/module/imp/importing.py b/pypy/module/imp/importing.py --- a/pypy/module/imp/importing.py +++ b/pypy/module/imp/importing.py @@ -70,7 +70,6 @@ @unwrap_spec(modulename='str0', level=int) def importhook(space, modulename, w_globals=None, w_locals=None, w_fromlist=None, level=0): # A minimal version, that can only import builtin and lib_pypy modules! - assert w_locals is w_globals assert level == 0 w_mod = check_sys_modules_w(space, modulename) _______________________________________________ pypy-commit mailing list pypy-commit@python.org https://mail.python.org/mailman/listinfo/pypy-commit