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

Function _find_spec_from_path

Lib/importlib/util.py:38–66  ·  view source on GitHub ↗

Return the spec for the specified module. First, sys.modules is checked to see if the module was already imported. If so, then sys.modules[name].__spec__ is returned. If that happens to be set to None, then ValueError is raised. If the module is not in sys.modules, then sys.meta_pat

(name, path=None)

Source from the content-addressed store, hash-verified

36
37
38def _find_spec_from_path(name, path=None):
39 """Return the spec for the specified module.
40
41 First, sys.modules is checked to see if the module was already imported. If
42 so, then sys.modules[name].__spec__ is returned. If that happens to be
43 set to None, then ValueError is raised. If the module is not in
44 sys.modules, then sys.meta_path is searched for a suitable spec with the
45 value of 'path' given to the finders. None is returned if no spec could
46 be found.
47
48 Dotted names do not have their parent packages implicitly imported. You will
49 most likely need to explicitly import all parent packages in the proper
50 order for a submodule to get the correct spec.
51
52 """
53 if name not in sys.modules:
54 return _find_spec(name, path)
55 else:
56 module = sys.modules[name]
57 if module is None:
58 return None
59 try:
60 spec = module.__spec__
61 except AttributeError:
62 raise ValueError(f'{name}.__spec__ is not set') from None
63 else:
64 if spec is None:
65 raise ValueError(f'{name}.__spec__ is None')
66 return spec
67
68
69def find_spec(name, package=None):

Callers

nothing calls this directly

Calls 1

_find_specFunction · 0.85

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…