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 = f"Call to deprecated function {func.__name__}. {instructions}"
24 
25  warnings.warn(message, category=DeprecatedWarning, stacklevel=2)
26 
27  return func(*args, **kwargs)
28 
29  instructions_doc = "Deprecated: " + instructions
30  if wrapper.__doc__ is None:
31  wrapper.__doc__ = instructions_doc
32  else:
33  wrapper.__doc__ = wrapper.__doc__.rstrip() + "\n\n" + instructions_doc
34  return wrapper
35 
36  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 Dec 22 2024 03:41:09