decorators.py 文件源码

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

项目:smc-python 作者: gabstopper 项目源码 文件源码
def deprecated(func_replacement):
    """
    Use this decorator on functions that are marked as deprecated.
    It takes a single argument of the function name it's being
    replaced with.
    """
    def _deprecated(func):
        @functools.wraps(func)
        def new_func(*args, **kwargs):
            warnings.simplefilter('always', DeprecationWarning) #turn off filter 
            warnings.warn(
                'Call to deprecated function {}. Use new function: {}() instead.'
                .format(func.__name__, func_replacement),
                category=DeprecationWarning, stacklevel=2)
            warnings.simplefilter('default', DeprecationWarning) #reset filter
            return func(*args, **kwargs)
        return new_func
    return _deprecated
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号