def get_unwrapped_func(func):
"""Get original function under decorator.
Decorator hides original function inside itself. But in some cases it's
important to get access to original function, for ex: for documentation.
Args:
func (function): function that can be potentially a decorator which
hides original function
Returns:
function: unwrapped function or the same function
"""
if not inspect.isfunction(func) and not inspect.ismethod(func):
return func
if func.__name__ != six.get_function_code(func).co_name:
for cell in six.get_function_closure(func):
obj = cell.cell_contents
if inspect.isfunction(obj):
if func.__name__ == six.get_function_code(obj).co_name:
return obj
else:
return get_unwrapped_func(obj)
return func
评论列表
文章目录