Commit 03ba9843 authored by Andreas Dedner's avatar Andreas Dedner

improve the deprecation decorator

parent 825c7853
import warnings
def deprecated(msg):
def deprecated(msg,name=None):
'''This is a decorator which can be used to mark functions
as deprecated. It will result in a warning being emitted
when the function is used.'''
def deprecated_decorator(func):
def new_func(*args, **kwargs):
if name is None:
funcName = func.__name__
else:
funcName = name
if msg:
print("Call to deprecated function/property `{}`.".format(func.__name__),msg)
print("Call to deprecated function/property `{}`.".format(funcName),msg)
else:
print("Call to deprecated function/property `{}`.".format(func.__name__))
# warnings.warn("Call to deprecated function {}.".format(func.__name__),
# category=DeprecationWarning)
# not DepracationWarning is ignored by default (could use FutureWarning)
print("Call to deprecated function/property `{}`.".format(funcName))
warnings.warn("Call to deprecated function {}.".format(funcName),
category=DeprecationWarning)
# note: DepracationWarning is ignored by default (could use FutureWarning)
# also the warning will be only shown once
return func(*args, **kwargs)
new_func.__name__ = func.__name__
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment