Skip to content

Commit 87f9edb

Browse files
committed
Fix load_module and load_package to handle namespace packages
Signed-off-by: Filipe Laíns <[email protected]>
1 parent 9a045fb commit 87f9edb

File tree

1 file changed

+8
-1
lines changed

1 file changed

+8
-1
lines changed

Lib/modulefinder.py

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -333,7 +333,7 @@ def import_module(self, partname, fqname, parent):
333333
def load_module(self, fqname, fp, pathname, file_info):
334334
suffix, mode, type = file_info
335335
self.msgin(2, "load_module", fqname, fp and "fp", pathname)
336-
if type == _PKG_DIRECTORY:
336+
if type in (_PKG_DIRECTORY, _NAMESPACE):
337337
m = self.load_package(fqname, pathname)
338338
self.msgout(2, "load_module ->", m)
339339
return m
@@ -458,6 +458,13 @@ def load_package(self, fqname, pathname):
458458
if newname:
459459
fqname = newname
460460
m = self.add_module(fqname)
461+
462+
# TODO: Update the type check once GH-119669 is merged.
463+
# if isinstance(pathname, importlib.machinery.NamespacePath):
464+
if 'NamespacePath' in type(pathname).__name__:
465+
m.__path__ = pathname
466+
return m
467+
461468
m.__file__ = pathname
462469
m.__path__ = [pathname]
463470

0 commit comments

Comments
 (0)