utils.py 文件源码

python
阅读 26 收藏 0 点赞 0 评论 0

项目:stepler 作者: Mirantis 项目源码 文件源码
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
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号