10 """Flags a method as deprecated.
12 instructions: A human-friendly string of instructions, such
13 as: 'Please migrate to add_proxy() ASAP.'
17 """This is a decorator which can be used to mark functions
18 as deprecated. It will result in a warning being emitted
19 when the function is used."""
21 @functools.wraps(func)
22 def wrapper(*args, **kwargs):
23 message = f
"Call to deprecated function {func.__name__}. {instructions}"
25 warnings.warn(message, category=DeprecatedWarning, stacklevel=2)
27 return func(*args, **kwargs)
29 instructions_doc =
"Deprecated: " + instructions
30 if wrapper.__doc__
is None:
31 wrapper.__doc__ = instructions_doc
33 wrapper.__doc__ = wrapper.__doc__.rstrip() +
"\n\n" + instructions_doc