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

Function _normalize_module

Lib/doctest.py:215–238  ·  view source on GitHub ↗

Return the module specified by `module`. In particular: - If `module` is a module, then return module. - If `module` is a string, then import and return the module with that name. - If `module` is None, then return the calling module. The calling module is ass

(module, depth=2)

Source from the content-addressed store, hash-verified

213 return flags
214
215def _normalize_module(module, depth=2):
216 """
217 Return the module specified by `module`. In particular:
218 - If `module` is a module, then return module.
219 - If `module` is a string, then import and return the
220 module with that name.
221 - If `module` is None, then return the calling module.
222 The calling module is assumed to be the module of
223 the stack frame at the given depth in the call stack.
224 """
225 if inspect.ismodule(module):
226 return module
227 elif isinstance(module, str):
228 return __import__(module, globals(), locals(), ["*"])
229 elif module is None:
230 try:
231 try:
232 return sys.modules[sys._getframemodulename(depth)]
233 except AttributeError:
234 return sys.modules[sys._getframe(depth).f_globals['__name__']]
235 except KeyError:
236 pass
237 else:
238 raise TypeError("Expected a module, string, or None")
239
240def _load_testfile(filename, package, module_relative, encoding):
241 if module_relative:

Callers 5

_load_testfileFunction · 0.85
DocTestSuiteFunction · 0.85
DocFileSuiteFunction · 0.85
testsourceFunction · 0.85
debugFunction · 0.85

Calls 2

__import__Function · 0.85
ismoduleMethod · 0.45

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…