deprecation.py
Go to the documentation of this file.
1 import functools
2 import warnings
3 
4 class DeprecatedWarning(UserWarning):
5  pass
6 
7 def deprecated(instructions):
8  """Flags a method as deprecated.
9  Args:
10  instructions: A human-friendly string of instructions, such
11  as: 'Please migrate to add_proxy() ASAP.'
12  """
13  def decorator(func):
14  '''This is a decorator which can be used to mark functions
15  as deprecated. It will result in a warning being emitted
16  when the function is used.'''
17  @functools.wraps(func)
18  def wrapper(*args, **kwargs):
19  message = 'Call to deprecated function {}. {}'.format(
20  func.__name__,
21  instructions)
22 
23  warnings.warn(message, category=DeprecatedWarning, stacklevel=2)
24 
25  return func(*args, **kwargs)
26 
27  instructions_doc = 'Deprecated: ' + instructions
28  if wrapper.__doc__ is None:
29  wrapper.__doc__ = instructions_doc
30  else:
31  wrapper.__doc__ = wrapper.__doc__.rstrip() + '\n\n' + instructions_doc
32  return wrapper
33 
34  return decorator
def deprecated(instructions)
Definition: deprecation.py:7


pinocchio
Author(s):
autogenerated on Fri Jun 23 2023 02:38:29