Skip to content

Make ILQ.answer raise ValueError rather than TypeError #2675

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Sep 24, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 11 additions & 8 deletions telegram/inline/inlinequery.py
Original file line number Diff line number Diff line change
Expand Up @@ -127,26 +127,29 @@ def answer(
) -> bool:
"""Shortcut for::

bot.answer_inline_query(update.inline_query.id,
*args,
current_offset=self.offset if auto_pagination else None,
**kwargs)
bot.answer_inline_query(
update.inline_query.id,
*args,
current_offset=self.offset if auto_pagination else None,
**kwargs
)

For the documentation of the arguments, please see
:meth:`telegram.Bot.answer_inline_query`.

.. versionchanged:: 14.0
Raises :class:`ValueError` instead of :class:`TypeError`.

Args:
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`.
Defaults to :obj:`False`.

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:
# We raise TypeError instead of ValueError for backwards compatibility with versions
# which didn't check this here but let Python do the checking
raise TypeError('current_offset and auto_pagination are mutually exclusive!')
raise ValueError('current_offset and auto_pagination are mutually exclusive!')
return self.bot.answer_inline_query(
inline_query_id=self.id,
current_offset=self.offset if auto_pagination else current_offset,
Expand Down
2 changes: 1 addition & 1 deletion tests/test_inlinequery.py
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,7 @@ def make_assertion(*_, **kwargs):
assert inline_query.answer(results=[])

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')

def test_answer_auto_pagination(self, monkeypatch, inline_query):
Expand Down
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy