FazBrowse GitHub Viewer | Trending |
URL:
| Home
Tools: [Download Repo ZIP]   [Original HTTPS Page]

Issue #20763: Fix importlib.machinery.PathFinder to support · python/cpython@26dd0ff · GitHub

Repository navigation

Commit 26dd0ff

Browse files
committed
Issue #20763: Fix importlib.machinery.PathFinder to support
PathEntryFinder instances which only define find_module(). Reported by Yukihiro Nakadaira.
1 parent d44cebb commit 26dd0ff

3 files changed

Lines changed: 26 additions & 2 deletions

File tree

‎Lib/importlib/_bootstrap.py‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1869,7 +1869,7 @@ def _legacy_get_spec(cls, fullname, finder):
18691869
loader, portions = finder.find_loader(fullname)
18701870
else:
18711871
loader = finder.find_module(fullname)
1872-
portions = None
1872+
portions = []
18731873
if loader is not None:
18741874
return spec_from_loader(fullname, loader)
18751875
spec = ModuleSpec(fullname, None)

‎Lib/test/test_importlib/import_/test_path.py‎

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -116,5 +116,29 @@ def test_None_on_sys_path(self):
116116
FinderTests, importlib=importlib, machinery=machinery)
117117

118118

119+
class PathEntryFinderTests:
120+
121+
def test_finder_with_failing_find_module(self):
122+
# PathEntryFinder with find_module() defined should work.
123+
# Issue #20763.
124+
class Finder:
125+
path_location = 'test_finder_with_find_module'
126+
def __init__(self, path):
127+
if path != self.path_location:
128+
raise ImportError
129+
130+
@staticmethod
131+
def find_module(fullname):
132+
return None
133+
134+
135+
with util.import_state(path=[Finder.path_location]+sys.path[:],
136+
path_hooks=[Finder]):
137+
self.machinery.PathFinder.find_spec('importlib')
138+
139+
Frozen_PEFTests, Source_PEFTests = util.test_both(
140+
PathEntryFinderTests, machinery=machinery)
141+
142+
119143
if __name__ == '__main__':
120144
unittest.main()

‎Python/importlib.h‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3365,7 +3365,7 @@ const unsigned char _Py_M__importlib[] = {
33653365
116,0,0,124,2,0,100,1,0,131,2,0,114,39,0,124,
33663366
2,0,106,1,0,124,1,0,131,1,0,92,2,0,125,3,
33673367
0,125,4,0,110,21,0,124,2,0,106,2,0,124,1,0,
3368-
131,1,0,125,3,0,100,0,0,125,4,0,124,3,0,100,
3368+
131,1,0,125,3,0,103,0,0,125,4,0,124,3,0,100,
33693369
0,0,107,9,0,114,85,0,116,3,0,124,1,0,124,3,
33703370
0,131,2,0,83,116,4,0,124,1,0,100,0,0,131,2,
33713371
0,125,5,0,124,4,0,124,5,0,95,5,0,124,5,0,

0 commit comments

Comments
 (0)

Back | FazBrowse Home | New Git URL