forked from ucloud/ucloud-sdk-python3
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdeco.py
More file actions
31 lines (24 loc) · 819 Bytes
/
Copy pathdeco.py
File metadata and controls
31 lines (24 loc) · 819 Bytes
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
import functools
import logging
logger = logging.getLogger("ucloud")
def deprecated(instead_of="", message=""):
"""deprecated is a decorator to mark a function is deprecated.
it will logging warning when this function called
>>> @deprecated(instead_of="new_function")
... def an_old_function():
... pass
"""
def deco(fn):
@functools.wraps(fn)
def wrapper(*args, **kwargs):
msg = [
"this function/method `{}` is deprecated".format(fn.__name__)
]
instead_of and msg.append(
"please use `{}` instead".format(instead_of)
)
message and msg.append(message)
logger.warning(", ".join(msg))
return fn(*args, **kwargs)
return wrapper
return deco