Skip to content

Commit ac47681

Browse files
authored
Remove Incorrect Warning About Defaults and ExtBot (python-telegram-bot#2553)
* Don't throw warning when passing defaults to ExtBot * Review
1 parent d08172b commit ac47681

2 files changed

Lines changed: 25 additions & 2 deletions

File tree

telegram/ext/extbot.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -101,8 +101,9 @@ def __init__(
101101
request=request,
102102
private_key=private_key,
103103
private_key_password=private_key_password,
104-
defaults=defaults,
105104
)
105+
# We don't pass this to super().__init__ to avoid the deprecation warning
106+
self.defaults = defaults
106107

107108
# set up callback_data
108109
if not isinstance(arbitrary_callback_data, bool):

tests/test_bot.py

Lines changed: 23 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@
5353
PollOption,
5454
)
5555
from telegram.constants import MAX_INLINE_QUERY_RESULTS
56-
from telegram.ext import ExtBot
56+
from telegram.ext import ExtBot, Defaults
5757
from telegram.error import BadRequest, InvalidToken, NetworkError, RetryAfter
5858
from telegram.ext.callbackdatacache import InvalidCallbackData
5959
from telegram.utils.helpers import (
@@ -65,6 +65,16 @@
6565
from tests.bots import FALLBACKS
6666

6767

68+
class ExtBotSubClass(ExtBot):
69+
# used for test_defaults_warning below
70+
pass
71+
72+
73+
class BotSubClass(Bot):
74+
# used for test_defaults_warning below
75+
pass
76+
77+
6878
@pytest.fixture(scope='class')
6979
def message(bot, chat_id):
7080
to_reply_to = bot.send_message(
@@ -2373,3 +2383,15 @@ def post(*args, **kwargs):
23732383
bot.arbitrary_callback_data = False
23742384
bot.callback_data_cache.clear_callback_data()
23752385
bot.callback_data_cache.clear_callback_queries()
2386+
2387+
@pytest.mark.parametrize(
2388+
'cls,warn', [(Bot, True), (BotSubClass, True), (ExtBot, False), (ExtBotSubClass, False)]
2389+
)
2390+
def test_defaults_warning(self, bot, recwarn, cls, warn):
2391+
defaults = Defaults()
2392+
cls(bot.token, defaults=defaults)
2393+
if warn:
2394+
assert len(recwarn) == 1
2395+
assert 'Passing Defaults to telegram.Bot is deprecated.' in str(recwarn[-1].message)
2396+
else:
2397+
assert len(recwarn) == 0

0 commit comments

Comments
 (0)