[pypy-svn] pypy default: Don't stick NullImporter in sys.path_importer_cache for any failed import, only for some of them (copied CPython's from logic here).
alex_gaynor
commits-noreply at bitbucket.org
Sun Jan 30 04:15:57 CET 2011
Author: Alex Gaynor <alex.gaynor at gmail.com>
Branch:
Changeset: r41468:99a2441b0317
Date: 2011-01-29 22:15 -0500
http://bitbucket.org/pypy/pypy/changeset/99a2441b0317/
Log: Don't stick NullImporter in sys.path_importer_cache for any failed
import, only for some of them (copied CPython's from logic here).
diff --git a/pypy/module/imp/test/test_app.py b/pypy/module/imp/test/test_app.py
--- a/pypy/module/imp/test/test_app.py
+++ b/pypy/module/imp/test/test_app.py
@@ -128,3 +128,12 @@
importer = self.imp.NullImporter("path")
assert importer.find_module(1, 2, 3, 4) is None
raises(ImportError, self.imp.NullImporter, os.getcwd())
+
+ def test_path_importer_cache(self):
+ import os
+ import sys
+
+ lib_pypy = os.path.abspath(
+ os.path.join(self.file_module, "..", "..", "..", "..", "..", "lib_pypy")
+ )
+ assert sys.path_importer_cache[lib_pypy] is None
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
@@ -112,7 +112,7 @@
w_locals=None, w_fromlist=None, level=-1):
modulename = name
space.timer.start_name("importhook", modulename)
- if not modulename and level < 0:
+ if not modulename and level < 0:
raise OperationError(
space.w_ValueError,
space.wrap("Empty module name"))
@@ -305,7 +305,14 @@
else:
break
if w_importer is None:
- w_importer = space.wrap(W_NullImporter(space))
+ try:
+ w_importer = space.call_function(
+ space.gettypefor(W_NullImporter), w_pathitem
+ )
+ except OperationError, e:
+ if e.match(space, space.w_ImportError):
+ return
+ raise
if space.is_true(w_importer):
space.setitem(w_path_importer_cache, w_pathitem, w_importer)
if space.is_true(w_importer):
@@ -822,7 +829,7 @@
def read_compiled_module(space, cpathname, strbuf):
""" Read a code object from a file and check it for validity """
-
+
w_marshal = space.getbuiltinmodule('marshal')
w_code = space.call_method(w_marshal, 'loads', space.wrap(strbuf))
pycode = space.interpclass_w(w_code)
@@ -909,4 +916,3 @@
os.unlink(cpathname)
except OSError:
pass
-
More information about the Pypy-commit
mailing list