Skip to content
Open
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
6 changes: 6 additions & 0 deletions changes/unreleased/5271.H8posH7FA8X3BZrmC52ueg.toml
Original file line number Diff line number Diff line change
@@ -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 = []
26 changes: 2 additions & 24 deletions src/telegram/_bot.py
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,6 @@
from telegram._utils.strings import to_camel_case
from telegram._utils.types import (
BaseUrl,
CorrectOptionID,
CorrectOptionIds,
FileInput,
JSONDict,
Expand All @@ -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 (
Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -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.

Expand Down
3 changes: 0 additions & 3 deletions src/telegram/_chat.py
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -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,
Expand Down
7 changes: 1 addition & 6 deletions src/telegram/_chatmember.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
3 changes: 0 additions & 3 deletions src/telegram/_message.py
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -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,
Expand Down
111 changes: 12 additions & 99 deletions src/telegram/_poll.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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):
"""
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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.
Expand Down Expand Up @@ -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.
Expand Down Expand Up @@ -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.
Expand Down Expand Up @@ -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.
Expand Down Expand Up @@ -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,
Expand All @@ -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
Expand All @@ -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(
Expand Down Expand Up @@ -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
Expand Down
3 changes: 0 additions & 3 deletions src/telegram/_user.py
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -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,
Expand Down
2 changes: 0 additions & 2 deletions src/telegram/_utils/types.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Loading
Loading