MCPcopy Create free account
hub / github.com/RT-Thread/env-windows / _normalize_module

Function _normalize_module

tools/python-3.11.9-amd64/Lib/doctest.py:195–212  ·  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

(module, depth=2)

Source from the content-addressed store, hash-verified

193 return flags
194
195def _normalize_module(module, depth=2):
196 """
197 Return the module specified by `module`. In particular:
198 - If `module` is a module, then return module.
199 - If `module` is a string, then import and return the
200 module with that name.
201 - If `module` is None, then return the calling module.
202 The calling module is assumed to be the module of
203 the stack frame at the given depth in the call stack.
204 """
205 if inspect.ismodule(module):
206 return module
207 elif isinstance(module, str):
208 return __import__(module, globals(), locals(), ["*"])
209 elif module is None:
210 return sys.modules[sys._getframe(depth).f_globals['__name__']]
211 else:
212 raise TypeError("Expected a module, string, or None")
213
214def _newline_convert(data):
215 # 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 1

__import__Function · 0.85

Tested by

no test coverage detected