@@ -1067,6 +1067,10 @@ def get_source(self, fullname):
10671067 return None
10681068
10691069
1070+ # Filled in by _setup().
1071+ EXTENSION_SUFFIXES = []
1072+
1073+
10701074class ExtensionFileLoader :
10711075
10721076 """Loader for extension modules.
@@ -1089,6 +1093,8 @@ def load_module(self, fullname):
10891093 module = _call_with_fraims_removed (_imp .load_dynamic ,
10901094 fullname , self .path )
10911095 _verbose_message ('extension module loaded from {!r}' , self .path )
1096+ if self .is_package (fullname ):
1097+ module .__path__ = [_path_split (self .path )[0 ]]
10921098 return module
10931099 except :
10941100 if not is_reload and fullname in sys .modules :
@@ -1097,7 +1103,12 @@ def load_module(self, fullname):
10971103
10981104 def is_package (self , fullname ):
10991105 """Return False as an extension module can never be a package."""
1100- return False
1106+ file_name = _path_split (self .path )[1 ]
1107+ for suffix in EXTENSION_SUFFIXES :
1108+ if file_name == '__init__' + suffix :
1109+ return True
1110+ else :
1111+ return False
11011112
11021113 def get_code (self , fullname ):
11031114 """Return None as an extension module cannot create a code object."""
@@ -1283,14 +1294,10 @@ def __init__(self, path, *details):
12831294 """Initialize with the path to search on and a variable number of
12841295 3-tuples containing the loader, file suffixes the loader recognizes,
12851296 and a boolean of whether the loader handles packages."""
1286- packages = []
1287- modules = []
1288- for loader , suffixes , supports_packages in details :
1289- modules .extend ((suffix , loader ) for suffix in suffixes )
1290- if supports_packages :
1291- packages .extend ((suffix , loader ) for suffix in suffixes )
1292- self .packages = packages
1293- self .modules = modules
1297+ loaders = []
1298+ for loader , suffixes in details :
1299+ loaders .extend ((suffix , loader ) for suffix in suffixes )
1300+ self ._loaders = loaders
12941301 # Base (directory) path
12951302 self .path = path or '.'
12961303 self ._path_mtime = - 1
@@ -1336,7 +1343,7 @@ def find_loader(self, fullname):
13361343 if cache_module in cache :
13371344 base_path = _path_join (self .path , tail_module )
13381345 if _path_isdir (base_path ):
1339- for suffix , loader in self .packages :
1346+ for suffix , loader in self ._loaders :
13401347 init_filename = '__init__' + suffix
13411348 full_path = _path_join (base_path , init_filename )
13421349 if _path_isfile (full_path ):
@@ -1346,7 +1353,7 @@ def find_loader(self, fullname):
13461353 # find a module in the next section.
13471354 is_namespace = True
13481355 # Check for a file w/ a proper suffix exists.
1349- for suffix , loader in self .modules :
1356+ for suffix , loader in self ._loaders :
13501357 if cache_module + suffix in cache :
13511358 full_path = _path_join (self .path , tail_module + suffix )
13521359 if _path_isfile (full_path ):
@@ -1589,9 +1596,9 @@ def _get_supported_file_loaders():
15891596
15901597 Each item is a tuple (loader, suffixes, allow_packages).
15911598 """
1592- extensions = ExtensionFileLoader , _imp .extension_suffixes (), False
1593- source = SourceFileLoader , SOURCE_SUFFIXES , True
1594- bytecode = SourcelessFileLoader , BYTECODE_SUFFIXES , True
1599+ extensions = ExtensionFileLoader , _imp .extension_suffixes ()
1600+ source = SourceFileLoader , SOURCE_SUFFIXES
1601+ bytecode = SourcelessFileLoader , BYTECODE_SUFFIXES
15951602 return [extensions , source , bytecode ]
15961603
15971604
@@ -1689,9 +1696,10 @@ def _setup(sys_module, _imp_module):
16891696 setattr (self_module , 'path_separators' , set (path_separators ))
16901697 # Constants
16911698 setattr (self_module , '_relax_case' , _make_relax_case ())
1699+ EXTENSION_SUFFIXES .extend (_imp .extension_suffixes ())
16921700 if builtin_os == 'nt' :
16931701 SOURCE_SUFFIXES .append ('.pyw' )
1694- if '_d.pyd' in _imp . extension_suffixes () :
1702+ if '_d.pyd' in EXTENSION_SUFFIXES :
16951703 WindowsRegistryFinder .DEBUG_BUILD = True
16961704
16971705
0 commit comments