-
Notifications
You must be signed in to change notification settings - Fork 4.2k
/
Copy pathdecorators.py
39 lines (28 loc) · 898 Bytes
/
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
"""
Function decorators.
"""
import typing as t
import warnings
import typing_extensions as te
from composio.utils import help_msg
T = te.TypeVar("T")
P = te.ParamSpec("P")
def deprecated(
version: str,
replacement: str,
) -> t.Callable[[t.Callable[P, T]], t.Callable[P, T]]:
"""
Mark a function as deprecated.
:param version: Version where this method will be deprecated.
:param replacement: Replacement for this method.
"""
def wrapper(func: t.Callable[P, T]) -> t.Callable[P, T]:
def new_func(*args: P.args, **kwargs: P.kwargs) -> T:
warnings.warn(
f"`{func.__name__}` is deprecated and will be removed on v{version}. "
f"Use `{replacement}` method instead." + help_msg(),
UserWarning,
)
return func(*args, **kwargs)
return new_func
return wrapper