[Python-checkins] cpython (3.4): Issue #20763: Fix importlib.machinery.PathFinder to support

larry.hastings python-checkins at python.org
Mon Mar 17 07:33:05 CET 2014


http://hg.python.org/cpython/rev/149be7000c11
changeset:   89774:149be7000c11
branch:      3.4
user:        Brett Cannon <brett at python.org>
date:        Wed Feb 26 18:26:49 2014 -0500
summary:
  Issue #20763: Fix importlib.machinery.PathFinder to support
PathEntryFinder instances which only define find_module().

Reported by Yukihiro Nakadaira.

files:
  Lib/importlib/_bootstrap.py                  |   2 +-
  Lib/test/test_importlib/import_/test_path.py |  24 ++++++++++
  Python/importlib.h                           |   2 +-
  3 files changed, 26 insertions(+), 2 deletions(-)


diff --git a/Lib/importlib/_bootstrap.py b/Lib/importlib/_bootstrap.py
--- a/Lib/importlib/_bootstrap.py
+++ b/Lib/importlib/_bootstrap.py
@@ -1869,7 +1869,7 @@
             loader, portions = finder.find_loader(fullname)
         else:
             loader = finder.find_module(fullname)
-            portions = None
+            portions = []
         if loader is not None:
             return spec_from_loader(fullname, loader)
         spec = ModuleSpec(fullname, None)
diff --git a/Lib/test/test_importlib/import_/test_path.py b/Lib/test/test_importlib/import_/test_path.py
--- a/Lib/test/test_importlib/import_/test_path.py
+++ b/Lib/test/test_importlib/import_/test_path.py
@@ -116,5 +116,29 @@
         FinderTests, importlib=importlib, machinery=machinery)
 
 
+class PathEntryFinderTests:
+
+    def test_finder_with_failing_find_module(self):
+        # PathEntryFinder with find_module() defined should work.
+        # Issue #20763.
+        class Finder:
+            path_location = 'test_finder_with_find_module'
+            def __init__(self, path):
+                if path != self.path_location:
+                    raise ImportError
+
+            @staticmethod
+            def find_module(fullname):
+                return None
+
+
+        with util.import_state(path=[Finder.path_location]+sys.path[:],
+                               path_hooks=[Finder]):
+            self.machinery.PathFinder.find_spec('importlib')
+
+Frozen_PEFTests, Source_PEFTests = util.test_both(
+        PathEntryFinderTests, machinery=machinery)
+
+
 if __name__ == '__main__':
     unittest.main()
diff --git a/Python/importlib.h b/Python/importlib.h
--- a/Python/importlib.h
+++ b/Python/importlib.h
[stripped]

-- 
Repository URL: http://hg.python.org/cpython


More information about the Python-checkins mailing list