MCPcopy Index your code
hub / github.com/RustPython/RustPython / _normalize_module

Function _normalize_module

Lib/doctest.py:216–239  ·  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

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

Callers 5

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

Calls 4

isinstanceFunction · 0.85
globalsFunction · 0.85
localsFunction · 0.85
__import__Function · 0.50

Tested by

no test coverage detected