mirror of
https://github.com/python-telegram-bot/python-telegram-bot.git
synced 2024-11-22 15:17:00 +01:00
Better deprecation warnings
Actually shows where in the users code the error happened, not just where the warning came from in our internal code
This commit is contained in:
parent
5a15d1b5d6
commit
8499dcc33c
1 changed files with 12 additions and 2 deletions
|
@ -21,8 +21,18 @@
|
|||
import warnings
|
||||
|
||||
|
||||
def warn_deprecate_obj(old, new):
|
||||
warnings.warn('{0} is being deprecated, please use {1} from now on'.format(old, new))
|
||||
# We use our own DeprecationWarning since they are muted by default and "UserWarning" makes it
|
||||
# seem like it's the user that issued the warning
|
||||
# We name it something else so that you don't get confused when you attempt to suppress it
|
||||
class TelegramDeprecationWarning(Warning):
|
||||
pass
|
||||
|
||||
|
||||
def warn_deprecate_obj(old, new, stacklevel=3):
|
||||
warnings.warn(
|
||||
'{0} is being deprecated, please use {1} from now on.'.format(old, new),
|
||||
category=TelegramDeprecationWarning,
|
||||
stacklevel=stacklevel)
|
||||
|
||||
|
||||
def deprecate(func, old, new):
|
||||
|
|
Loading…
Reference in a new issue