summaryrefslogtreecommitdiffstats
path: root/venv/lib/python3.9/site-packages/altair/utils/deprecation.py
diff options
context:
space:
mode:
Diffstat (limited to 'venv/lib/python3.9/site-packages/altair/utils/deprecation.py')
-rw-r--r--venv/lib/python3.9/site-packages/altair/utils/deprecation.py70
1 files changed, 70 insertions, 0 deletions
diff --git a/venv/lib/python3.9/site-packages/altair/utils/deprecation.py b/venv/lib/python3.9/site-packages/altair/utils/deprecation.py
new file mode 100644
index 00000000..9deca223
--- /dev/null
+++ b/venv/lib/python3.9/site-packages/altair/utils/deprecation.py
@@ -0,0 +1,70 @@
+import warnings
+import functools
+
+
+class AltairDeprecationWarning(UserWarning):
+ pass
+
+
+def deprecated(message=None):
+ """Decorator to deprecate a function or class.
+
+ Parameters
+ ----------
+ message : string (optional)
+ The deprecation message
+ """
+
+ def wrapper(obj):
+ return _deprecate(obj, message=message)
+
+ return wrapper
+
+
+def _deprecate(obj, name=None, message=None):
+ """Return a version of a class or function that raises a deprecation warning.
+
+ Parameters
+ ----------
+ obj : class or function
+ The object to create a deprecated version of.
+ name : string (optional)
+ The name of the deprecated object
+ message : string (optional)
+ The deprecation message
+
+ Returns
+ -------
+ deprecated_obj :
+ The deprecated version of obj
+
+ Examples
+ --------
+ >>> class Foo(object): pass
+ >>> OldFoo = _deprecate(Foo, "OldFoo")
+ >>> f = OldFoo() # doctest: +SKIP
+ AltairDeprecationWarning: alt.OldFoo is deprecated. Use alt.Foo instead.
+ """
+ if message is None:
+ message = "alt.{} is deprecated. Use alt.{} instead." "".format(
+ name, obj.__name__
+ )
+ if isinstance(obj, type):
+ return type(
+ name,
+ (obj,),
+ {
+ "__doc__": obj.__doc__,
+ "__init__": _deprecate(obj.__init__, "__init__", message),
+ },
+ )
+ elif callable(obj):
+
+ @functools.wraps(obj)
+ def new_obj(*args, **kwargs):
+ warnings.warn(message, AltairDeprecationWarning)
+ return obj(*args, **kwargs)
+
+ return new_obj
+ else:
+ raise ValueError("Cannot deprecate object of type {}".format(type(obj)))