mirror of
https://github.com/python-telegram-bot/python-telegram-bot.git
synced 2026-06-19 07:35:19 +00:00
Remove functionality deprecated in Bot API 10.0
This commit is contained in:
+2
-24
@@ -106,7 +106,6 @@ from telegram._utils.repr import build_repr_with_selected_attrs
|
||||
from telegram._utils.strings import to_camel_case
|
||||
from telegram._utils.types import (
|
||||
BaseUrl,
|
||||
CorrectOptionID,
|
||||
CorrectOptionIds,
|
||||
FileInput,
|
||||
JSONDict,
|
||||
@@ -120,7 +119,7 @@ from telegram.error import EndPointNotFound, InvalidToken
|
||||
from telegram.request import BaseRequest, RequestData
|
||||
from telegram.request._httpxrequest import HTTPXRequest
|
||||
from telegram.request._requestparameter import RequestParameter
|
||||
from telegram.warnings import PTBDeprecationWarning, PTBUserWarning
|
||||
from telegram.warnings import PTBUserWarning
|
||||
|
||||
if TYPE_CHECKING:
|
||||
from telegram import (
|
||||
@@ -7376,9 +7375,6 @@ CUSTOM_EMOJI_IDENTIFIER_LIMIT` custom emoji identifiers can be specified.
|
||||
is_anonymous: bool | None = None,
|
||||
type: str | None = None, # pylint: disable=redefined-builtin
|
||||
allows_multiple_answers: bool | None = None,
|
||||
# tags: deprecated in 22.8, to be removed
|
||||
# replaced by `correct_option_ids`
|
||||
correct_option_id: CorrectOptionID | None = None,
|
||||
is_closed: bool | None = None,
|
||||
disable_notification: ODVInput[bool] = DEFAULT_NONE,
|
||||
reply_markup: "ReplyMarkup | None" = None,
|
||||
@@ -7443,12 +7439,6 @@ CUSTOM_EMOJI_IDENTIFIER_LIMIT` custom emoji identifiers can be specified.
|
||||
:tg-const:`telegram.Poll.REGULAR`, defaults to :tg-const:`telegram.Poll.REGULAR`.
|
||||
allows_multiple_answers (:obj:`bool`, optional): :obj:`True`, if the poll allows
|
||||
multiple answers, defaults to :obj:`False`.
|
||||
correct_option_id (:obj:`int`, optional): 0-based identifier of the correct answer
|
||||
option, required for polls in quiz mode.
|
||||
|
||||
.. deprecated:: 22.8
|
||||
Bot API 9.6 replaces this with :paramref:`correct_option_ids` instead.
|
||||
|
||||
explanation (:obj:`str`, optional): Text that is shown when a user chooses an incorrect
|
||||
answer or taps on the lamp icon in a quiz-style poll,
|
||||
0-:tg-const:`telegram.Poll.MAX_EXPLANATION_LENGTH` characters with at most
|
||||
@@ -7596,18 +7586,6 @@ CUSTOM_EMOJI_IDENTIFIER_LIMIT` custom emoji identifiers can be specified.
|
||||
:class:`telegram.Message`: On success, the sent Message is returned.
|
||||
"""
|
||||
|
||||
if correct_option_id is not None:
|
||||
warn(
|
||||
PTBDeprecationWarning(
|
||||
version="22.8",
|
||||
message="Bot API 9.6 deprecated `correct_option_id` in favour of "
|
||||
"`correct_option_ids`, please use that.",
|
||||
),
|
||||
stacklevel=2,
|
||||
)
|
||||
if correct_option_ids is None:
|
||||
correct_option_ids = [correct_option_id]
|
||||
|
||||
data: JSONDict = {
|
||||
"chat_id": chat_id,
|
||||
"question": question,
|
||||
@@ -8414,7 +8392,7 @@ CUSTOM_EMOJI_IDENTIFIER_LIMIT` custom emoji identifiers can be specified.
|
||||
found or copied, they are skipped. Service messages, paid media messages, giveaway
|
||||
messages, giveaway winners messages, and invoice messages can't be copied. A quiz poll can
|
||||
be copied only if the value
|
||||
of the field :attr:`telegram.Poll.correct_option_id` is known to the bot. The method is
|
||||
of the field :attr:`telegram.Poll.correct_option_ids` is known to the bot. The method is
|
||||
analogous to the method :meth:`forward_messages`, but the copied messages don't have a
|
||||
link to the original message. Album grouping is kept for copied messages.
|
||||
|
||||
|
||||
@@ -33,7 +33,6 @@ from telegram._telegramobject import TelegramObject
|
||||
from telegram._utils import enum
|
||||
from telegram._utils.defaultvalue import DEFAULT_NONE
|
||||
from telegram._utils.types import (
|
||||
CorrectOptionID,
|
||||
CorrectOptionIds,
|
||||
FileInput,
|
||||
JSONDict,
|
||||
@@ -2358,7 +2357,6 @@ class _ChatBase(TelegramObject):
|
||||
is_anonymous: bool | None = None,
|
||||
type: str | None = None,
|
||||
allows_multiple_answers: bool | None = None,
|
||||
correct_option_id: CorrectOptionID | None = None,
|
||||
is_closed: bool | None = None,
|
||||
disable_notification: ODVInput[bool] = DEFAULT_NONE,
|
||||
reply_markup: "ReplyMarkup | None" = None,
|
||||
@@ -2413,7 +2411,6 @@ class _ChatBase(TelegramObject):
|
||||
is_anonymous=is_anonymous,
|
||||
type=type, # pylint=pylint,
|
||||
allows_multiple_answers=allows_multiple_answers,
|
||||
correct_option_id=correct_option_id,
|
||||
allows_revoting=allows_revoting,
|
||||
shuffle_options=shuffle_options,
|
||||
correct_option_ids=correct_option_ids,
|
||||
|
||||
@@ -631,18 +631,13 @@ class ChatMemberRestricted(ChatMember):
|
||||
can_send_video_notes: bool,
|
||||
can_send_voice_notes: bool,
|
||||
can_edit_tag: bool,
|
||||
can_react_to_messages: bool,
|
||||
tag: str | None = None,
|
||||
# tags: 22.8
|
||||
# temporarily optional to make it not breaking
|
||||
can_react_to_messages: bool | None = None,
|
||||
*,
|
||||
api_kwargs: JSONDict | None = None,
|
||||
):
|
||||
super().__init__(status=ChatMember.RESTRICTED, user=user, api_kwargs=api_kwargs)
|
||||
|
||||
if can_react_to_messages is None:
|
||||
raise TypeError("`can_react_to_messages` is required and cannot be None")
|
||||
|
||||
with self._unfrozen():
|
||||
self.is_member: bool = is_member
|
||||
self.can_change_info: bool = can_change_info
|
||||
|
||||
@@ -81,7 +81,6 @@ from telegram._utils.defaultvalue import DEFAULT_NONE, DefaultValue
|
||||
from telegram._utils.entities import parse_message_entities, parse_message_entity
|
||||
from telegram._utils.strings import TextEncoding
|
||||
from telegram._utils.types import (
|
||||
CorrectOptionID,
|
||||
CorrectOptionIds,
|
||||
JSONDict,
|
||||
MarkdownVersion,
|
||||
@@ -3663,7 +3662,6 @@ class Message(MaybeInaccessibleMessage):
|
||||
is_anonymous: bool | None = None,
|
||||
type: str | None = None, # pylint: disable=redefined-builtin
|
||||
allows_multiple_answers: bool | None = None,
|
||||
correct_option_id: CorrectOptionID | None = None,
|
||||
is_closed: bool | None = None,
|
||||
disable_notification: ODVInput[bool] = DEFAULT_NONE,
|
||||
reply_markup: "ReplyMarkup | None" = None,
|
||||
@@ -3739,7 +3737,6 @@ class Message(MaybeInaccessibleMessage):
|
||||
is_anonymous=is_anonymous,
|
||||
type=type,
|
||||
allows_multiple_answers=allows_multiple_answers,
|
||||
correct_option_id=correct_option_id,
|
||||
allows_revoting=allows_revoting,
|
||||
shuffle_options=shuffle_options,
|
||||
correct_option_ids=correct_option_ids,
|
||||
|
||||
+12
-99
@@ -51,8 +51,6 @@ from telegram._utils.datetime import (
|
||||
from telegram._utils.defaultvalue import DEFAULT_NONE
|
||||
from telegram._utils.entities import parse_message_entities, parse_message_entity
|
||||
from telegram._utils.types import JSONDict, ODVInput, TimePeriod
|
||||
from telegram._utils.warnings import warn
|
||||
from telegram.warnings import PTBDeprecationWarning
|
||||
|
||||
if TYPE_CHECKING:
|
||||
from telegram import Bot, InputPollOptionMedia, MaybeInaccessibleMessage
|
||||
@@ -234,30 +232,6 @@ class InputPollOption(TelegramObject):
|
||||
|
||||
self._freeze()
|
||||
|
||||
# tags: deprecated 22.8
|
||||
@classmethod
|
||||
def de_json(cls, data: JSONDict, bot: "Bot | None" = None) -> "InputPollOption":
|
||||
"""See :meth:`telegram.TelegramObject.de_json`. The :paramref:`media` field will
|
||||
not be included for deserialization.
|
||||
|
||||
.. deprecated:: 22.8
|
||||
This class is input only and will be removed in the next version.
|
||||
"""
|
||||
warn(
|
||||
PTBDeprecationWarning(
|
||||
"22.8",
|
||||
"`InputPollOption.de_json` is deprecated. This class is input only and will be "
|
||||
"removed in the next version. The `media` field will not be included for "
|
||||
"deserialization.",
|
||||
),
|
||||
stacklevel=2,
|
||||
)
|
||||
data = cls._parse_data(data)
|
||||
|
||||
data["text_entities"] = de_list_optional(data.get("text_entities"), MessageEntity, bot)
|
||||
|
||||
return super().de_json(data=data, bot=bot)
|
||||
|
||||
|
||||
class PollOption(TelegramObject):
|
||||
"""
|
||||
@@ -348,20 +322,15 @@ class PollOption(TelegramObject):
|
||||
self,
|
||||
text: str,
|
||||
voter_count: int,
|
||||
persistent_id: str,
|
||||
text_entities: Sequence[MessageEntity] | None = None,
|
||||
added_by_user: User | None = None,
|
||||
added_by_chat: Chat | None = None,
|
||||
addition_date: dtm.datetime | None = None,
|
||||
media: PollMedia | None = None,
|
||||
# tags: required in 22.8, bot api 9.6
|
||||
# temporarily optional to avoid breaking changes
|
||||
persistent_id: str | None = None,
|
||||
*,
|
||||
api_kwargs: JSONDict | None = None,
|
||||
):
|
||||
if persistent_id is None:
|
||||
raise TypeError("`persistent_id` is a required argument since Bot API 9.6")
|
||||
|
||||
super().__init__(api_kwargs=api_kwargs)
|
||||
self.text: str = text
|
||||
self.voter_count: int = voter_count
|
||||
@@ -515,17 +484,12 @@ class PollAnswer(TelegramObject):
|
||||
self,
|
||||
poll_id: str,
|
||||
option_ids: Sequence[int],
|
||||
option_persistent_ids: Sequence[str],
|
||||
user: User | None = None,
|
||||
voter_chat: Chat | None = None,
|
||||
# tags: required in 22.8, bot api 9.6
|
||||
# temporarily optional to avoid breaking changes
|
||||
option_persistent_ids: Sequence[str] | None = None,
|
||||
*,
|
||||
api_kwargs: JSONDict | None = None,
|
||||
):
|
||||
if option_persistent_ids is None:
|
||||
raise TypeError("`option_persistent_ids` is a required argument since Bot API 9.6")
|
||||
|
||||
super().__init__(api_kwargs=api_kwargs)
|
||||
self.poll_id: str = poll_id
|
||||
self.voter_chat: Chat | None = voter_chat
|
||||
@@ -805,17 +769,15 @@ class Poll(TelegramObject):
|
||||
is_anonymous (:obj:`bool`): :obj:`True`, if the poll is anonymous.
|
||||
type (:obj:`str`): Poll type, currently can be :attr:`REGULAR` or :attr:`QUIZ`.
|
||||
allows_multiple_answers (:obj:`bool`): :obj:`True`, if the poll allows multiple answers.
|
||||
allows_revoting (:obj:`bool`): :obj:`True`, if the poll allows to
|
||||
change the chosen answer options.
|
||||
|
||||
.. versionadded:: 22.8
|
||||
members_only (:obj:`bool`): :obj:`True`, if voting is limited to users who have been
|
||||
members of the chat where the poll was originally sent for more than
|
||||
:tg-const:`telegram.Poll.MIN_MEMBERSHIP_HOURS` hours.
|
||||
|
||||
.. versionadded:: 22.8
|
||||
correct_option_id (:obj:`int`, optional): A zero based identifier of the correct answer
|
||||
option. Available only for closed polls in the quiz mode, which were sent
|
||||
(not forwarded), by the bot or to a private chat with the bot.
|
||||
|
||||
.. deprecated:: 22.8
|
||||
Use :paramref:`correct_option_ids` instead.
|
||||
explanation (:obj:`str`, optional): Text that is shown when a user chooses an incorrect
|
||||
answer or taps on the lamp icon in a quiz-style poll,
|
||||
0-:tg-const:`telegram.Poll.MAX_EXPLANATION_LENGTH` characters.
|
||||
@@ -847,10 +809,6 @@ class Poll(TelegramObject):
|
||||
in poll questions.
|
||||
|
||||
.. versionadded:: 21.2
|
||||
allows_revoting (:obj:`bool`, optional): :obj:`True`, if the poll allows to
|
||||
change the chosenanswer options.
|
||||
|
||||
.. versionadded:: 22.8
|
||||
correct_option_ids (Sequence[:class:`int`], optional): Array of 0-based identifiers of
|
||||
the correct answer options. Available only for polls in quiz mode which are closed or
|
||||
were sent (not forwarded) by the bot or to the private chat with the bot.
|
||||
@@ -888,6 +846,10 @@ class Poll(TelegramObject):
|
||||
is_anonymous (:obj:`bool`): :obj:`True`, if the poll is anonymous.
|
||||
type (:obj:`str`): Poll type, currently can be :attr:`REGULAR` or :attr:`QUIZ`.
|
||||
allows_multiple_answers (:obj:`bool`): :obj:`True`, if the poll allows multiple answers.
|
||||
allows_revoting (:obj:`bool`): :obj:`True`, if the poll
|
||||
allows to change the chosen answer options
|
||||
|
||||
.. versionadded:: 22.8
|
||||
members_only (:obj:`bool`): :obj:`True`, if voting is limited to users who have been
|
||||
members of the chat where the poll was originally sent for more than
|
||||
:tg-const:`telegram.Poll.MIN_MEMBERSHIP_HOURS` hours.
|
||||
@@ -925,10 +887,6 @@ class Poll(TelegramObject):
|
||||
This list is empty if the question does not contain entities.
|
||||
|
||||
.. versionadded:: 21.2
|
||||
allows_revoting (:obj:`bool`): :obj:`True`, if the poll
|
||||
allows to change the chosenanswer options
|
||||
|
||||
.. versionadded:: 22.8
|
||||
correct_option_ids (tuple[:class:`int`]): Array of 0-based identifiers of the
|
||||
correct answer options. Available only for polls in quiz mode which are closed or were
|
||||
sent (not forwarded) by the bot or to the private chat with the bot.
|
||||
@@ -989,20 +947,13 @@ class Poll(TelegramObject):
|
||||
is_anonymous: bool,
|
||||
type: str, # pylint: disable=redefined-builtin
|
||||
allows_multiple_answers: bool,
|
||||
# tags: deprecated 22.8
|
||||
# Removed in bot api 9.6:
|
||||
correct_option_id: int | None = None,
|
||||
# ---
|
||||
allows_revoting: bool,
|
||||
members_only: bool,
|
||||
explanation: str | None = None,
|
||||
explanation_entities: Sequence[MessageEntity] | None = None,
|
||||
open_period: TimePeriod | None = None,
|
||||
close_date: dtm.datetime | None = None,
|
||||
question_entities: Sequence[MessageEntity] | None = None,
|
||||
# tags: required in 22.8
|
||||
# temporarily optional to avoid breaking changes
|
||||
allows_revoting: bool | None = None,
|
||||
members_only: bool | None = None,
|
||||
# ---
|
||||
correct_option_ids: Sequence[int] | None = None,
|
||||
description: str | None = None,
|
||||
description_entities: Sequence[MessageEntity] | None = None,
|
||||
@@ -1012,12 +963,6 @@ class Poll(TelegramObject):
|
||||
*,
|
||||
api_kwargs: JSONDict | None = None,
|
||||
):
|
||||
if allows_revoting is None:
|
||||
raise TypeError("`allows_revoting` is a required argument since Bot API 9.6")
|
||||
|
||||
if members_only is None:
|
||||
raise TypeError("`members_only` is a required argument since Bot API 10.0")
|
||||
|
||||
super().__init__(api_kwargs=api_kwargs)
|
||||
self.id: str = id
|
||||
self.question: str = question
|
||||
@@ -1030,19 +975,6 @@ class Poll(TelegramObject):
|
||||
self.allows_revoting: bool = allows_revoting
|
||||
self.members_only: bool = members_only
|
||||
|
||||
# tag: deprecated 22.8
|
||||
if correct_option_id is not None:
|
||||
warn(
|
||||
PTBDeprecationWarning(
|
||||
"22.8",
|
||||
"The parameter `correct_option_id` is deprecated. "
|
||||
"Use `correct_option_ids` instead.",
|
||||
),
|
||||
stacklevel=2,
|
||||
)
|
||||
if correct_option_ids is None:
|
||||
correct_option_ids = [correct_option_id]
|
||||
|
||||
self.correct_option_ids: tuple[int, ...] = parse_sequence_arg(correct_option_ids)
|
||||
self.description: str | None = description
|
||||
self.description_entities: tuple[MessageEntity, ...] = parse_sequence_arg(
|
||||
@@ -1249,25 +1181,6 @@ class Poll(TelegramObject):
|
||||
|
||||
return parse_message_entities(self.description, self.description_entities, types)
|
||||
|
||||
@property
|
||||
def correct_option_id(self) -> int | None:
|
||||
"""A zero based identifier of the correct answer
|
||||
option. Available only for closed polls in the quiz mode, which were sent
|
||||
(not forwarded), by the bot or to a private chat with the bot.
|
||||
|
||||
.. deprecated:: 22.8
|
||||
Use :attr:`correct_option_ids` instead.
|
||||
"""
|
||||
warn(
|
||||
PTBDeprecationWarning(
|
||||
"22.8",
|
||||
"The attribute `correct_option_id` is deprecated. "
|
||||
"Use `correct_option_ids` instead.",
|
||||
),
|
||||
stacklevel=2,
|
||||
)
|
||||
return self.correct_option_ids[0] if self.correct_option_ids else None
|
||||
|
||||
REGULAR: Final[str] = constants.PollType.REGULAR
|
||||
""":const:`telegram.constants.PollType.REGULAR`"""
|
||||
QUIZ: Final[str] = constants.PollType.QUIZ
|
||||
|
||||
@@ -28,7 +28,6 @@ from telegram._menubutton import MenuButton
|
||||
from telegram._telegramobject import TelegramObject
|
||||
from telegram._utils.defaultvalue import DEFAULT_NONE
|
||||
from telegram._utils.types import (
|
||||
CorrectOptionID,
|
||||
CorrectOptionIds,
|
||||
JSONDict,
|
||||
ODVInput,
|
||||
@@ -1818,7 +1817,6 @@ class User(TelegramObject):
|
||||
is_anonymous: bool | None = None,
|
||||
type: str | None = None,
|
||||
allows_multiple_answers: bool | None = None,
|
||||
correct_option_id: CorrectOptionID | None = None,
|
||||
is_closed: bool | None = None,
|
||||
disable_notification: ODVInput[bool] = DEFAULT_NONE,
|
||||
reply_markup: "ReplyMarkup | None" = None,
|
||||
@@ -1876,7 +1874,6 @@ class User(TelegramObject):
|
||||
is_anonymous=is_anonymous,
|
||||
type=type, # pylint=pylint,
|
||||
allows_multiple_answers=allows_multiple_answers,
|
||||
correct_option_id=correct_option_id,
|
||||
allows_revoting=allows_revoting,
|
||||
shuffle_options=shuffle_options,
|
||||
correct_option_ids=correct_option_ids,
|
||||
|
||||
@@ -91,8 +91,6 @@ HTTPVersion: TypeAlias = Literal["1.1", "2.0", "2"]
|
||||
|
||||
.. versionadded:: 20.4"""
|
||||
|
||||
CorrectOptionID: TypeAlias = Literal[0, 1, 2, 3, 4, 5, 6, 7, 8, 9] # pylint: disable=invalid-name
|
||||
|
||||
CorrectOptionIds: TypeAlias = Sequence[Literal[0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11]]
|
||||
"""
|
||||
.. versionadded:: 22.8
|
||||
|
||||
@@ -101,7 +101,6 @@ from telegram._utils.logging import get_logger
|
||||
from telegram._utils.repr import build_repr_with_selected_attrs
|
||||
from telegram._utils.types import (
|
||||
BaseUrl,
|
||||
CorrectOptionID,
|
||||
CorrectOptionIds,
|
||||
FileInput,
|
||||
JSONDict,
|
||||
@@ -3269,7 +3268,6 @@ class ExtBot(Bot, Generic[RLARGS]):
|
||||
is_anonymous: bool | None = None,
|
||||
type: str | None = None, # pylint: disable=redefined-builtin
|
||||
allows_multiple_answers: bool | None = None,
|
||||
correct_option_id: CorrectOptionID | None = None,
|
||||
is_closed: bool | None = None,
|
||||
disable_notification: ODVInput[bool] = DEFAULT_NONE,
|
||||
reply_markup: "ReplyMarkup | None" = None,
|
||||
@@ -3315,7 +3313,6 @@ class ExtBot(Bot, Generic[RLARGS]):
|
||||
is_anonymous=is_anonymous,
|
||||
type=type,
|
||||
allows_multiple_answers=allows_multiple_answers,
|
||||
correct_option_id=correct_option_id,
|
||||
is_closed=is_closed,
|
||||
disable_notification=disable_notification,
|
||||
reply_to_message_id=reply_to_message_id,
|
||||
|
||||
+5
-39
@@ -105,7 +105,7 @@ from telegram.error import BadRequest, EndPointNotFound, InvalidToken, TimedOut
|
||||
from telegram.ext import ExtBot, InvalidCallbackData
|
||||
from telegram.helpers import escape_markdown
|
||||
from telegram.request import BaseRequest, HTTPXRequest, RequestData
|
||||
from telegram.warnings import PTBDeprecationWarning, PTBUserWarning
|
||||
from telegram.warnings import PTBUserWarning
|
||||
from tests.auxil.bot_method_checks import check_defaults_handling
|
||||
from tests.auxil.ci_bots import FALLBACKS
|
||||
from tests.auxil.envvars import GITHUB_ACTIONS
|
||||
@@ -3003,40 +3003,6 @@ class TestBotWithoutRequest:
|
||||
|
||||
await offline_bot.set_chat_member_tag(1234, 5678, "This is a tag")
|
||||
|
||||
async def test_send_poll_warn_correct_option_id(self, offline_bot, monkeypatch, recwarn):
|
||||
async def make_first_assert(url, request_data: RequestData, *args, **kwargs):
|
||||
assert request_data.parameters.get("correct_option_ids") == [1]
|
||||
assert request_data.parameters.get("correct_option_id") is None
|
||||
return make_message("dummy reply").to_dict()
|
||||
|
||||
async def make_second_assert(url, request_data: RequestData, *args, **kwargs):
|
||||
assert request_data.parameters.get("correct_option_ids") == [1, 2]
|
||||
assert request_data.parameters.get("correct_option_id") is None
|
||||
return make_message("dummy reply").to_dict()
|
||||
|
||||
monkeypatch.setattr(offline_bot.request, "post", make_first_assert)
|
||||
|
||||
await offline_bot.send_poll(
|
||||
1,
|
||||
question="question",
|
||||
options=["option1", "option2"],
|
||||
correct_option_id=1,
|
||||
)
|
||||
|
||||
w = recwarn.pop()
|
||||
assert issubclass(w.category, PTBDeprecationWarning)
|
||||
assert "correct_option_id" in str(w.message)
|
||||
|
||||
# Test that correct_option_ids takes priority when both correct_option_id(s) are given
|
||||
monkeypatch.setattr(offline_bot.request, "post", make_second_assert)
|
||||
assert await offline_bot.send_poll(
|
||||
1,
|
||||
question="question",
|
||||
options=["option1", "option2"],
|
||||
correct_option_id=1,
|
||||
correct_option_ids=[1, 2],
|
||||
)
|
||||
|
||||
# TODO: If we create a managed bot, we could test this for real
|
||||
async def test_get_managed_bot_token(self, offline_bot, monkeypatch):
|
||||
|
||||
@@ -3349,7 +3315,7 @@ class TestBotWithRequest:
|
||||
question=question,
|
||||
options=answers,
|
||||
type=Poll.QUIZ,
|
||||
correct_option_id=2,
|
||||
correct_option_ids=[2],
|
||||
is_closed=True,
|
||||
explanation=explanation,
|
||||
explanation_parse_mode=ParseMode.MARKDOWN_V2,
|
||||
@@ -3388,7 +3354,7 @@ class TestBotWithRequest:
|
||||
assert poll.total_voter_count == 0
|
||||
|
||||
message_quiz = await quiz_task
|
||||
assert message_quiz.poll.correct_option_id == 2
|
||||
assert message_quiz.poll.correct_option_ids == (2,)
|
||||
assert message_quiz.poll.type == Poll.QUIZ
|
||||
assert message_quiz.poll.is_closed
|
||||
assert message_quiz.poll.explanation == "Here is a link"
|
||||
@@ -3475,7 +3441,7 @@ class TestBotWithRequest:
|
||||
chat_id,
|
||||
"question",
|
||||
options=["a", "b"],
|
||||
correct_option_id=0,
|
||||
correct_option_ids=[0],
|
||||
type=Poll.QUIZ,
|
||||
explanation=test_string,
|
||||
explanation_entities=entities,
|
||||
@@ -3526,7 +3492,7 @@ class TestBotWithRequest:
|
||||
question=question,
|
||||
options=answers,
|
||||
type=Poll.QUIZ,
|
||||
correct_option_id=2,
|
||||
correct_option_ids=[2],
|
||||
is_closed=True,
|
||||
explanation=explanation_markdown,
|
||||
**i,
|
||||
|
||||
@@ -684,18 +684,6 @@ class TestChatMemberRestrictedWithoutRequest(ChatMemberTestBase):
|
||||
"tag": chat_member_restricted.tag,
|
||||
}
|
||||
|
||||
def test_can_react_to_messages_raises(self, chat_member_restricted):
|
||||
with pytest.raises(
|
||||
TypeError, match="`can_react_to_messages` is required and cannot be None"
|
||||
):
|
||||
ChatMemberRestricted(
|
||||
*[
|
||||
getattr(chat_member_restricted, k)
|
||||
for k in chat_member_restricted.__slots__
|
||||
if k != "can_react_to_messages"
|
||||
]
|
||||
)
|
||||
|
||||
def test_equality(self, chat_member_restricted):
|
||||
a = chat_member_restricted
|
||||
b = deepcopy(chat_member_restricted)
|
||||
|
||||
@@ -86,10 +86,7 @@ class ParamTypeCheckingExceptions:
|
||||
# too complex to compare/predict with official API
|
||||
# structure: class/method_name: {param_name: reduced form of annotation}
|
||||
COMPLEX_TYPES = {
|
||||
"send_poll": {
|
||||
# "correct_option_id": int,
|
||||
"correct_option_ids": Sequence[int]
|
||||
},
|
||||
"send_poll": {"correct_option_ids": Sequence[int]},
|
||||
"get_file": {
|
||||
"file_id": str, # actual: Union[str, objs_with_file_id_attr]
|
||||
},
|
||||
@@ -185,10 +182,6 @@ PTB_EXTRA_PARAMS = {
|
||||
"InputProfilePhoto": {"type"}, # attributes common to all subclasses
|
||||
"InputPollOptionMedia": {"args", "kwargs"}, # UnionType's __init__ signature
|
||||
"InputPollMedia": {"args", "kwargs"}, # UnionType's __init__ signature
|
||||
# backwards compatibility for api 10.0 changes
|
||||
# tags: deprecated NEXT.VERSION, bot api 10.0
|
||||
"Poll": {"correct_option_id"},
|
||||
"send_poll": {"correct_option_id"},
|
||||
}
|
||||
|
||||
|
||||
@@ -244,13 +237,7 @@ def ignored_param_requirements(object_name: str) -> set[str]:
|
||||
|
||||
|
||||
# Arguments that are optional arguments for now for backwards compatibility
|
||||
BACKWARDS_COMPAT_KWARGS: dict[str, set[str]] = {
|
||||
"PollOption": {"persistent_id"},
|
||||
"PollAnswer": {"option_persistent_ids"},
|
||||
"Poll": {"allows_revoting", "members_only"},
|
||||
"ChatMemberRestricted": {"can_react_to_messages"},
|
||||
"send_poll": {"correct_option_id"},
|
||||
}
|
||||
BACKWARDS_COMPAT_KWARGS: dict[str, set[str]] = {}
|
||||
|
||||
|
||||
def backwards_compat_kwargs(object_name: str) -> set[str]:
|
||||
|
||||
+6
-94
@@ -78,30 +78,6 @@ class TestInputPollOptionWithoutRequest(InputPollOptionTestBase):
|
||||
"duplicate slot"
|
||||
)
|
||||
|
||||
# tags: deprecated NEXT.VERSION
|
||||
def test_de_json(self):
|
||||
json_dict = {
|
||||
"text": self.text,
|
||||
"text_parse_mode": self.text_parse_mode,
|
||||
"text_entities": [e.to_dict() for e in self.text_entities],
|
||||
}
|
||||
input_poll_option = InputPollOption.de_json(json_dict, None)
|
||||
assert input_poll_option.api_kwargs == {}
|
||||
|
||||
assert input_poll_option.text == self.text
|
||||
assert input_poll_option.text_parse_mode == self.text_parse_mode
|
||||
assert input_poll_option.text_entities == tuple(self.text_entities)
|
||||
|
||||
def test_de_json_deprecated(self, recwarn):
|
||||
InputPollOption.de_json({"text": self.text}, None)
|
||||
|
||||
assert len(recwarn) == 1
|
||||
assert "`InputPollOption.de_json` is deprecated" in str(recwarn[0].message)
|
||||
assert "The `media` field will not be included for deserialization" in str(
|
||||
recwarn[0].message
|
||||
)
|
||||
assert recwarn[0].category is PTBDeprecationWarning
|
||||
|
||||
def test_to_dict(self, input_poll_option):
|
||||
input_poll_option_dict = input_poll_option.to_dict()
|
||||
|
||||
@@ -343,11 +319,6 @@ class TestPollOptionWithoutRequest(PollOptionTestBase):
|
||||
assert poll_option.parse_entities(MessageEntity.BOLD) == {entity: "test"}
|
||||
assert poll_option.parse_entities() == {entity: "test", entity_2: "option"}
|
||||
|
||||
def test_persistent_id_required_workaround(self):
|
||||
# tags: deprecated NEXT.VERSION, bot api 9.6
|
||||
with pytest.raises(TypeError, match="`persistent_id` is a required"):
|
||||
PollOption(self.text, self.voter_count)
|
||||
|
||||
def test_equality(self):
|
||||
a = PollOption("text", 1, persistent_id="persistent_id")
|
||||
b = PollOption("text", 1, persistent_id="persistent_id")
|
||||
@@ -388,9 +359,9 @@ def poll_answer():
|
||||
return PollAnswer(
|
||||
PollAnswerTestBase.poll_id,
|
||||
PollAnswerTestBase.option_ids,
|
||||
PollAnswerTestBase.option_persistent_ids,
|
||||
PollAnswerTestBase.user,
|
||||
PollAnswerTestBase.voter_chat,
|
||||
PollAnswerTestBase.option_persistent_ids,
|
||||
)
|
||||
|
||||
|
||||
@@ -430,19 +401,12 @@ class TestPollAnswerWithoutRequest(PollAnswerTestBase):
|
||||
assert poll_answer_dict["voter_chat"] == poll_answer.voter_chat.to_dict()
|
||||
assert poll_answer_dict["option_persistent_ids"] == list(poll_answer.option_persistent_ids)
|
||||
|
||||
def test_persistent_id_required_workaround(self):
|
||||
# tags: deprecated NEXT.VERSION, bot api 9.6
|
||||
with pytest.raises(TypeError, match="`option_persistent_ids` is a required"):
|
||||
PollAnswer(poll_id=123, option_ids=[2], user=self.user, voter_chat=self.voter_chat)
|
||||
|
||||
def test_equality(self):
|
||||
a = PollAnswer(123, [2], self.user, self.voter_chat, option_persistent_ids=["2"])
|
||||
b = PollAnswer(123, [2], self.user, Chat(1, ""), option_persistent_ids=["2"])
|
||||
c = PollAnswer(
|
||||
123, [2], User(1, "first", False), self.voter_chat, option_persistent_ids=["2"]
|
||||
)
|
||||
d = PollAnswer(123, [1, 2], self.user, self.voter_chat, option_persistent_ids=["1", "2"])
|
||||
e = PollAnswer(456, [2], self.user, self.voter_chat, option_persistent_ids=["2"])
|
||||
a = PollAnswer(123, [2], ["2"], self.user, self.voter_chat)
|
||||
b = PollAnswer(123, [2], ["2"], self.user, Chat(1, ""))
|
||||
c = PollAnswer(123, [2], ["2"], User(1, "first", False), self.voter_chat)
|
||||
d = PollAnswer(123, [1, 2], ["1", "2"], self.user, self.voter_chat)
|
||||
e = PollAnswer(456, [2], ["2"], self.user, self.voter_chat)
|
||||
f = PollOption("Text", 1, persistent_id="persistent_id")
|
||||
|
||||
assert a == b
|
||||
@@ -663,58 +627,6 @@ class TestPollWithoutRequest(PollTestBase):
|
||||
assert "`open_period` will be of type `datetime.timedelta`" in str(recwarn[0].message)
|
||||
assert recwarn[0].category is PTBDeprecationWarning
|
||||
|
||||
def test_correct_option_id_deprecated(self, recwarn, poll):
|
||||
poll.correct_option_id
|
||||
|
||||
assert len(recwarn) == 1
|
||||
assert "The attribute `correct_option_id` is deprecated" in str(recwarn[0].message)
|
||||
assert recwarn[0].category is PTBDeprecationWarning
|
||||
|
||||
poll = Poll(
|
||||
PollTestBase.id_,
|
||||
PollTestBase.question,
|
||||
PollTestBase.options,
|
||||
PollTestBase.total_voter_count,
|
||||
PollTestBase.is_closed,
|
||||
PollTestBase.is_anonymous,
|
||||
PollTestBase.type,
|
||||
PollTestBase.allows_multiple_answers,
|
||||
correct_option_id=1,
|
||||
allows_revoting=PollTestBase.allows_revoting,
|
||||
members_only=PollTestBase.members_only,
|
||||
)
|
||||
assert poll.correct_option_ids == (1,)
|
||||
|
||||
def test_allows_revoting_required_workaround(self):
|
||||
# tags: deprecated NEXT.VERSION, bot api 9.6
|
||||
with pytest.raises(TypeError, match="`allows_revoting` is a required"):
|
||||
Poll(
|
||||
self.id_,
|
||||
self.question,
|
||||
self.options,
|
||||
self.total_voter_count,
|
||||
self.is_closed,
|
||||
self.is_anonymous,
|
||||
self.type,
|
||||
self.allows_multiple_answers,
|
||||
members_only=self.members_only,
|
||||
)
|
||||
|
||||
def test_members_only_required_workaround(self):
|
||||
# tags: deprecated NEXT.VERSION, bot api 10.0
|
||||
with pytest.raises(TypeError, match="`members_only` is a required"):
|
||||
Poll(
|
||||
self.id_,
|
||||
self.question,
|
||||
self.options,
|
||||
self.total_voter_count,
|
||||
self.is_closed,
|
||||
self.is_anonymous,
|
||||
self.type,
|
||||
self.allows_multiple_answers,
|
||||
allows_revoting=self.allows_revoting,
|
||||
)
|
||||
|
||||
def test_equality(self):
|
||||
a = Poll(
|
||||
123,
|
||||
|
||||
Reference in New Issue
Block a user