/
decorators.py
43 lines (34 loc) · 1.18 KB
/
decorators.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
# -*- coding: utf-8 -*-
import functools
import warnings
__all__ = ['deprecated']
def deprecated(use_instead, notes=None):
"""Mark functions as deprecated.
This decorator will result in a warning being emitted when the decorated
function is used.
Parameters
----------
use_instead : str
The name of the function to use instead.
notes : str, optional (default=None)
Additional notes to add to the warning message.
"""
if notes is None:
notes = ""
else:
notes = " " + notes
def wrapped_func(func):
@functools.wraps(func)
def _inner(*args, **kwargs):
warnings.simplefilter('always', DeprecationWarning) # un-filter
msg = ("{0} is deprecated and will be removed in a future "
"release of pmdarima. Use {1} instead.{2}"
.format(func.__name__, use_instead, notes))
warnings.warn(
msg,
category=DeprecationWarning,
stacklevel=2)
warnings.simplefilter('default', DeprecationWarning) # re-filter
return func(*args, **kwargs)
return _inner
return wrapped_func