summaryrefslogtreecommitdiffstats
path: root/Lib
diff options
context:
space:
mode:
authorBrett Cannon <brett@python.org>2014-02-26 23:26:49 (GMT)
committerBrett Cannon <brett@python.org>2014-02-26 23:26:49 (GMT)
commit26dd0ff075bcfcdc6eebe584dce55dfd2f1b1537 (patch)
treef6f258474b3045c3f05a1b2d59b38a92255a0620 /Lib
parentd44cebb0f50b7c541691b9516c5c1717d2a510b1 (diff)
downloadcpython-26dd0ff075bcfcdc6eebe584dce55dfd2f1b1537.zip
cpython-26dd0ff075bcfcdc6eebe584dce55dfd2f1b1537.tar.gz
cpython-26dd0ff075bcfcdc6eebe584dce55dfd2f1b1537.tar.bz2
Issue #20763: Fix importlib.machinery.PathFinder to support
PathEntryFinder instances which only define find_module(). Reported by Yukihiro Nakadaira.
Diffstat (limited to 'Lib')
-rw-r--r--Lib/importlib/_bootstrap.py2
-rw-r--r--Lib/test/test_importlib/import_/test_path.py24
2 files changed, 25 insertions, 1 deletions
diff --git a/Lib/importlib/_bootstrap.py b/Lib/importlib/_bootstrap.py
index 4864024..beaa9b3 100644
--- a/Lib/importlib/_bootstrap.py
+++ b/Lib/importlib/_bootstrap.py
@@ -1869,7 +1869,7 @@ class PathFinder:
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
index 713e754..1274f8c 100644
--- a/Lib/test/test_importlib/import_/test_path.py
+++ b/Lib/test/test_importlib/import_/test_path.py
@@ -116,5 +116,29 @@ Frozen_FinderTests, Source_FinderTests = util.test_both(
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()