def _find_function_module(func):
"""
@return: The module that defines the given function.
@rtype: C{module}
@param func: The function whose module should be found.
@type func: C{function}
"""
if hasattr(func, '__module__'):
return func.__module__
try:
module = inspect.getmodule(func)
if module: return module.__name__
except KeyboardInterrupt: raise
except: pass
# This fallback shouldn't usually be needed. But it is needed in
# a couple special cases (including using epydoc to document
# itself). In particular, if a module gets loaded twice, using
# two different names for the same file, then this helps.
for module in sys.modules.values():
if (hasattr(module, '__dict__') and
hasattr(func, 'func_globals') and
func.func_globals is module.__dict__):
return module.__name__
return None
#////////////////////////////////////////////////////////////
# Introspection Dispatch Table
#////////////////////////////////////////////////////////////
评论列表
文章目录