From 8499dcc33cb47e7a7dcaa38977c1914f11777b84 Mon Sep 17 00:00:00 2001 From: Jacob Bom Date: Thu, 25 May 2017 13:53:35 +0200 Subject: [PATCH] Better deprecation warnings Actually shows where in the users code the error happened, not just where the warning came from in our internal code --- telegram/utils/deprecate.py | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) diff --git a/telegram/utils/deprecate.py b/telegram/utils/deprecate.py index af06e1b02..5cbec860e 100644 --- a/telegram/utils/deprecate.py +++ b/telegram/utils/deprecate.py @@ -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):