deprecation.py
Go to the documentation of this file.
1 import functools
2 import warnings
3 
4 
5 class DeprecatedWarning(UserWarning):
6  pass
7 
8 
9 def deprecated(instructions):
10  """Flags a method as deprecated.
11  Args:
12  instructions: A human-friendly string of instructions, such
13  as: 'Please migrate to add_proxy() ASAP.'
14  """
15 
16  def decorator(func):
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."""
20 
21  @functools.wraps(func)
22  def wrapper(*args, **kwargs):
23  message = "Call to deprecated function {}. {}".format(
24  func.__name__, instructions
25  )
26 
27  warnings.warn(message, category=DeprecatedWarning, stacklevel=2)
28 
29  return func(*args, **kwargs)
30 
31  instructions_doc = "Deprecated: " + instructions
32  if wrapper.__doc__ is None:
33  wrapper.__doc__ = instructions_doc
34  else:
35  wrapper.__doc__ = wrapper.__doc__.rstrip() + "\n\n" + instructions_doc
36  return wrapper
37 
38  return decorator
pinocchio.deprecation.deprecated
def deprecated(instructions)
Definition: deprecation.py:9
pinocchio.deprecation.DeprecatedWarning
Definition: deprecation.py:5


pinocchio
Author(s):
autogenerated on Sun Jun 16 2024 02:43:09