1
0
mirror of https://github.com/eternnoir/pyTelegramBotAPI.git synced 2023-08-10 21:12:57 +03:00

replaced old deprecated decorator

This commit is contained in:
SwissCorePy
2021-06-30 13:47:39 +02:00
parent 073d7fb6a7
commit 791d65e95a
2 changed files with 12 additions and 16 deletions

View File

@ -420,7 +420,7 @@ def generate_random_token():
return ''.join(random.sample(string.ascii_letters, 16))
def deprecated_dec(warn: bool=False, alternative: Optional[Callable]=None):
def deprecated(warn: bool=False, alternative: Optional[Callable]=None):
"""
Use this decorator to mark functions as deprecated.
When the function is used, an info (or warning if `warn` is True) is logged.
@ -439,18 +439,3 @@ def deprecated_dec(warn: bool=False, alternative: Optional[Callable]=None):
return wrapper
return decorator
def deprecated(func):
"""This is a decorator which can be used to mark functions
as deprecated. It will result in a warning being emitted
when the function is used."""
# https://stackoverflow.com/a/30253848/441814
@functools.wraps(func)
def new_func(*args, **kwargs):
warnings.simplefilter('always', DeprecationWarning) # turn off filter
warnings.warn("Call to deprecated function {}.".format(func.__name__),
category=DeprecationWarning,
stacklevel=2)
warnings.simplefilter('default', DeprecationWarning) # reset filter
return func(*args, **kwargs)
return new_func