X Tutup
Skip to content

Commit 8499dcc

Browse files
committed
Better deprecation warnings
Actually shows where in the users code the error happened, not just where the warning came from in our internal code
1 parent 5a15d1b commit 8499dcc

File tree

1 file changed

+12
-2
lines changed

1 file changed

+12
-2
lines changed

telegram/utils/deprecate.py

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,8 +21,18 @@
2121
import warnings
2222

2323

24-
def warn_deprecate_obj(old, new):
25-
warnings.warn('{0} is being deprecated, please use {1} from now on'.format(old, new))
24+
# We use our own DeprecationWarning since they are muted by default and "UserWarning" makes it
25+
# seem like it's the user that issued the warning
26+
# We name it something else so that you don't get confused when you attempt to suppress it
27+
class TelegramDeprecationWarning(Warning):
28+
pass
29+
30+
31+
def warn_deprecate_obj(old, new, stacklevel=3):
32+
warnings.warn(
33+
'{0} is being deprecated, please use {1} from now on.'.format(old, new),
34+
category=TelegramDeprecationWarning,
35+
stacklevel=stacklevel)
2636

2737

2838
def deprecate(func, old, new):

0 commit comments

Comments
 (0)
X Tutup