MCPcopy Index your code
hub / github.com/python/cpython / _get_spec

Method _get_spec

Lib/importlib/_bootstrap_external.py:1234–1260  ·  view source on GitHub ↗

Find the loader or namespace_path for this module/package name.

(cls, fullname, path, target=None)

Source from the content-addressed store, hash-verified

1232
1233 @classmethod
1234 def _get_spec(cls, fullname, path, target=None):
1235 """Find the loader or namespace_path for this module/package name."""
1236 # If this ends up being a namespace package, namespace_path is
1237 # the list of paths that will become its __path__
1238 namespace_path = []
1239 for entry in path:
1240 if not isinstance(entry, str):
1241 continue
1242 finder = cls._path_importer_cache(entry)
1243 if finder is not None:
1244 spec = finder.find_spec(fullname, target)
1245 if spec is None:
1246 continue
1247 if spec.loader is not None:
1248 return spec
1249 portions = spec.submodule_search_locations
1250 if portions is None:
1251 raise ImportError('spec missing loader')
1252 # This is possibly part of a namespace package.
1253 # Remember these path entries (if any) for when we
1254 # create a namespace package, and continue iterating
1255 # on path.
1256 namespace_path.extend(portions)
1257 else:
1258 spec = _bootstrap.ModuleSpec(fullname, None)
1259 spec.submodule_search_locations = namespace_path
1260 return spec
1261
1262 @classmethod
1263 def find_spec(cls, fullname, path=None, target=None):

Callers 1

find_specMethod · 0.45

Calls 3

_path_importer_cacheMethod · 0.80
find_specMethod · 0.45
extendMethod · 0.45

Tested by

no test coverage detected