Make InlineQuery.answer Raise ValueError (#2675)

This commit is contained in:
Bibo-Joshi 2021-09-24 07:55:17 +02:00 committed by Hinrich Mahler
parent c440c255a7
commit ce94651490
2 changed files with 12 additions and 9 deletions

View file

@ -127,26 +127,29 @@ class InlineQuery(TelegramObject):
) -> bool: ) -> bool:
"""Shortcut for:: """Shortcut for::
bot.answer_inline_query(update.inline_query.id, bot.answer_inline_query(
*args, update.inline_query.id,
current_offset=self.offset if auto_pagination else None, *args,
**kwargs) current_offset=self.offset if auto_pagination else None,
**kwargs
)
For the documentation of the arguments, please see For the documentation of the arguments, please see
:meth:`telegram.Bot.answer_inline_query`. :meth:`telegram.Bot.answer_inline_query`.
.. versionchanged:: 14.0
Raises :class:`ValueError` instead of :class:`TypeError`.
Args: Args:
auto_pagination (:obj:`bool`, optional): If set to :obj:`True`, :attr:`offset` will be auto_pagination (:obj:`bool`, optional): If set to :obj:`True`, :attr:`offset` will be
passed as :attr:`current_offset` to :meth:`telegram.Bot.answer_inline_query`. passed as :attr:`current_offset` to :meth:`telegram.Bot.answer_inline_query`.
Defaults to :obj:`False`. Defaults to :obj:`False`.
Raises: Raises:
TypeError: If both :attr:`current_offset` and :attr:`auto_pagination` are supplied. ValueError: If both :attr:`current_offset` and :attr:`auto_pagination` are supplied.
""" """
if current_offset and auto_pagination: if current_offset and auto_pagination:
# We raise TypeError instead of ValueError for backwards compatibility with versions raise ValueError('current_offset and auto_pagination are mutually exclusive!')
# which didn't check this here but let Python do the checking
raise TypeError('current_offset and auto_pagination are mutually exclusive!')
return self.bot.answer_inline_query( return self.bot.answer_inline_query(
inline_query_id=self.id, inline_query_id=self.id,
current_offset=self.offset if auto_pagination else current_offset, current_offset=self.offset if auto_pagination else current_offset,

View file

@ -92,7 +92,7 @@ class TestInlineQuery:
assert inline_query.answer(results=[]) assert inline_query.answer(results=[])
def test_answer_error(self, inline_query): def test_answer_error(self, inline_query):
with pytest.raises(TypeError, match='mutually exclusive'): with pytest.raises(ValueError, match='mutually exclusive'):
inline_query.answer(results=[], auto_pagination=True, current_offset='foobar') inline_query.answer(results=[], auto_pagination=True, current_offset='foobar')
def test_answer_auto_pagination(self, monkeypatch, inline_query): def test_answer_auto_pagination(self, monkeypatch, inline_query):