Remove Incorrect Warning About Defaults and ExtBot (#2553)

* Don't throw warning when passing defaults to ExtBot

* Review
This commit is contained in:
Bibo-Joshi 2021-06-10 12:03:44 +02:00 committed by GitHub
parent d08172b4b0
commit ac4768155f
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 25 additions and 2 deletions

View file

@ -101,8 +101,9 @@ class ExtBot(telegram.bot.Bot):
request=request, request=request,
private_key=private_key, private_key=private_key,
private_key_password=private_key_password, private_key_password=private_key_password,
defaults=defaults,
) )
# We don't pass this to super().__init__ to avoid the deprecation warning
self.defaults = defaults
# set up callback_data # set up callback_data
if not isinstance(arbitrary_callback_data, bool): if not isinstance(arbitrary_callback_data, bool):

View file

@ -53,7 +53,7 @@ from telegram import (
PollOption, PollOption,
) )
from telegram.constants import MAX_INLINE_QUERY_RESULTS from telegram.constants import MAX_INLINE_QUERY_RESULTS
from telegram.ext import ExtBot from telegram.ext import ExtBot, Defaults
from telegram.error import BadRequest, InvalidToken, NetworkError, RetryAfter from telegram.error import BadRequest, InvalidToken, NetworkError, RetryAfter
from telegram.ext.callbackdatacache import InvalidCallbackData from telegram.ext.callbackdatacache import InvalidCallbackData
from telegram.utils.helpers import ( from telegram.utils.helpers import (
@ -65,6 +65,16 @@ from tests.conftest import expect_bad_request, check_defaults_handling, GITHUB_A
from tests.bots import FALLBACKS from tests.bots import FALLBACKS
class ExtBotSubClass(ExtBot):
# used for test_defaults_warning below
pass
class BotSubClass(Bot):
# used for test_defaults_warning below
pass
@pytest.fixture(scope='class') @pytest.fixture(scope='class')
def message(bot, chat_id): def message(bot, chat_id):
to_reply_to = bot.send_message( to_reply_to = bot.send_message(
@ -2373,3 +2383,15 @@ class TestBot:
bot.arbitrary_callback_data = False bot.arbitrary_callback_data = False
bot.callback_data_cache.clear_callback_data() bot.callback_data_cache.clear_callback_data()
bot.callback_data_cache.clear_callback_queries() bot.callback_data_cache.clear_callback_queries()
@pytest.mark.parametrize(
'cls,warn', [(Bot, True), (BotSubClass, True), (ExtBot, False), (ExtBotSubClass, False)]
)
def test_defaults_warning(self, bot, recwarn, cls, warn):
defaults = Defaults()
cls(bot.token, defaults=defaults)
if warn:
assert len(recwarn) == 1
assert 'Passing Defaults to telegram.Bot is deprecated.' in str(recwarn[-1].message)
else:
assert len(recwarn) == 0