From 430bde6e0e2d0a60f59c6011fb3f11af6b63cb4e Mon Sep 17 00:00:00 2001 From: Harshil <37377066+harshil21@users.noreply.github.com> Date: Wed, 17 Jun 2026 16:35:29 -0400 Subject: [PATCH 1/2] Remove functionality deprecated in Bot API 10.0 --- src/telegram/_bot.py | 26 +------ src/telegram/_chat.py | 3 - src/telegram/_chatmember.py | 7 +- src/telegram/_message.py | 3 - src/telegram/_poll.py | 111 ++++-------------------------- src/telegram/_user.py | 3 - src/telegram/_utils/types.py | 2 - src/telegram/ext/_extbot.py | 3 - tests/test_bot.py | 44 ++---------- tests/test_chatmember.py | 12 ---- tests/test_official/exceptions.py | 17 +---- tests/test_poll.py | 100 ++------------------------- 12 files changed, 28 insertions(+), 303 deletions(-) diff --git a/src/telegram/_bot.py b/src/telegram/_bot.py index 3cb94e3ad07..fe325d4b87a 100644 --- a/src/telegram/_bot.py +++ b/src/telegram/_bot.py @@ -106,7 +106,6 @@ from telegram._utils.strings import to_camel_case from telegram._utils.types import ( BaseUrl, - CorrectOptionID, CorrectOptionIds, FileInput, JSONDict, @@ -120,7 +119,7 @@ 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 @@ async def send_poll( 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 @@ async def send_poll( :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 @@ async def send_poll( :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 @@ async def copy_messages( 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. diff --git a/src/telegram/_chat.py b/src/telegram/_chat.py index fcdec9a6d71..9c3ac7b120a 100644 --- a/src/telegram/_chat.py +++ b/src/telegram/_chat.py @@ -33,7 +33,6 @@ 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 @@ async def send_poll( 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 @@ async def send_poll( 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, diff --git a/src/telegram/_chatmember.py b/src/telegram/_chatmember.py index eafacdfedba..52e12d8fc3e 100644 --- a/src/telegram/_chatmember.py +++ b/src/telegram/_chatmember.py @@ -631,18 +631,13 @@ def __init__( 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 diff --git a/src/telegram/_message.py b/src/telegram/_message.py index c52351df67d..0eab6e314f9 100644 --- a/src/telegram/_message.py +++ b/src/telegram/_message.py @@ -81,7 +81,6 @@ 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 @@ async def reply_poll( 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 @@ async def reply_poll( 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, diff --git a/src/telegram/_poll.py b/src/telegram/_poll.py index dd3689492ac..17541bff388 100644 --- a/src/telegram/_poll.py +++ b/src/telegram/_poll.py @@ -51,8 +51,6 @@ 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 @@ def __init__( 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 @@ def __init__( 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 @@ def __init__( 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 @@ def __init__( 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 @@ def __init__( *, 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 @@ def __init__( 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 @@ def parse_description_entities( 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 diff --git a/src/telegram/_user.py b/src/telegram/_user.py index eb95639da8c..e8d4aae0a62 100644 --- a/src/telegram/_user.py +++ b/src/telegram/_user.py @@ -28,7 +28,6 @@ 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 @@ async def send_poll( 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 @@ async def send_poll( 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, diff --git a/src/telegram/_utils/types.py b/src/telegram/_utils/types.py index a6c70545593..89f7dea93e6 100644 --- a/src/telegram/_utils/types.py +++ b/src/telegram/_utils/types.py @@ -91,8 +91,6 @@ .. 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 diff --git a/src/telegram/ext/_extbot.py b/src/telegram/ext/_extbot.py index 0d8ef596e50..6e54f3a7574 100644 --- a/src/telegram/ext/_extbot.py +++ b/src/telegram/ext/_extbot.py @@ -101,7 +101,6 @@ from telegram._utils.repr import build_repr_with_selected_attrs from telegram._utils.types import ( BaseUrl, - CorrectOptionID, CorrectOptionIds, FileInput, JSONDict, @@ -3269,7 +3268,6 @@ async def send_poll( 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 @@ async def send_poll( 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, diff --git a/tests/test_bot.py b/tests/test_bot.py index 5f9fb22a3eb..aed852c7b99 100644 --- a/tests/test_bot.py +++ b/tests/test_bot.py @@ -105,7 +105,7 @@ 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 @@ async def make_assertion(url, request_data: RequestData, *args, **kwargs): 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 @@ async def test_send_and_stop_poll(self, bot, super_group_id, reply_markup): 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 @@ async def test_send_and_stop_poll(self, bot, super_group_id, reply_markup): 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 @@ async def test_send_poll_explanation_entities(self, bot, chat_id): 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 @@ async def test_send_poll_default_parse_mode(self, default_bot, super_group_id): question=question, options=answers, type=Poll.QUIZ, - correct_option_id=2, + correct_option_ids=[2], is_closed=True, explanation=explanation_markdown, **i, diff --git a/tests/test_chatmember.py b/tests/test_chatmember.py index ead273bdbd2..a321f035fac 100644 --- a/tests/test_chatmember.py +++ b/tests/test_chatmember.py @@ -684,18 +684,6 @@ def test_to_dict(self, chat_member_restricted): "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) diff --git a/tests/test_official/exceptions.py b/tests/test_official/exceptions.py index d063909db9d..b19c8af32f1 100644 --- a/tests/test_official/exceptions.py +++ b/tests/test_official/exceptions.py @@ -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 @@ class ParamTypeCheckingExceptions: "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]: diff --git a/tests/test_poll.py b/tests/test_poll.py index 10d39a2fe98..3b65d622ffa 100644 --- a/tests/test_poll.py +++ b/tests/test_poll.py @@ -78,30 +78,6 @@ def test_slot_behaviour(self, input_poll_option): "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 @@ def test_parse_entities(self, poll_option): 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 @@ def test_to_dict(self, poll_answer): 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 @@ def test_time_period_int_deprecated(self, recwarn, PTB_TIMEDELTA, poll): 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, From 2877bc068b4d08b978c3c980105079db447d715c Mon Sep 17 00:00:00 2001 From: harshil21 <37377066+harshil21@users.noreply.github.com> Date: Wed, 17 Jun 2026 20:39:58 +0000 Subject: [PATCH 2/2] Add chango fragment for PR #5271 --- changes/unreleased/5271.H8posH7FA8X3BZrmC52ueg.toml | 6 ++++++ 1 file changed, 6 insertions(+) create mode 100644 changes/unreleased/5271.H8posH7FA8X3BZrmC52ueg.toml diff --git a/changes/unreleased/5271.H8posH7FA8X3BZrmC52ueg.toml b/changes/unreleased/5271.H8posH7FA8X3BZrmC52ueg.toml new file mode 100644 index 00000000000..dda449cb8e0 --- /dev/null +++ b/changes/unreleased/5271.H8posH7FA8X3BZrmC52ueg.toml @@ -0,0 +1,6 @@ +breaking = "Remove functionality deprecated in Bot API 10.0" +features = "Remove functionality deprecated in Bot API 10.0" +[[pull_requests]] +uid = "5271" +author_uids = ["harshil21"] +closes_threads = []