-
Notifications
You must be signed in to change notification settings - Fork 7
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
1 changed file
with
52 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
import functools | ||
import warnings | ||
|
||
|
||
def deprecation_warning(successor, msg=None): | ||
# TODO (ahalev) use obj_linkcode here | ||
""" | ||
Decorator for warning of future deprecation | ||
Raises a DeprecationWarning on the wrapped function and suggests using `successor` instead. | ||
If msg is not None, raises a future warning with said message. In this case `successor` is ignored. | ||
""" | ||
|
||
def decorator(func): | ||
|
||
@functools.wraps(func) | ||
def wrapper(self, *args, **kwargs): | ||
_msg = msg or f"Function '{func.__qualname__}' is deprecated and will be removed in a future version. "\ | ||
f"Use '{successor}' instead." | ||
|
||
warnings.warn(_msg, category=DeprecationWarning) | ||
|
||
return func(self, *args, **kwargs) | ||
return wrapper | ||
return decorator | ||
|
||
|
||
def deprecation_err(successor, msg=None): | ||
# TODO (ahalev) use obj_linkcode here | ||
""" | ||
Decorator for warning of future deprecation | ||
Raises a DeprecationWarning on the wrapped function and suggests using `successor` instead. | ||
If msg is not None, raises a future warning with said message. In this case `successor` is ignored. | ||
""" | ||
|
||
def decorator(func): | ||
|
||
@functools.wraps(func) | ||
def wrapper(self, *args, **kwargs): | ||
# TODO (ahalev) get this version | ||
_msg = msg or f"Function '{func.__name__}' is deprecated as of version {'version'}. "\ | ||
f"Use '{successor}' instead." | ||
|
||
raise DeprecatedError(_msg) | ||
|
||
return wrapper | ||
return decorator | ||
|
||
|
||
class DeprecatedError(Exception): | ||
pass |