Remove Functionality Deprecated in API 7.0 (#4114)

This commit is contained in:
Bibo-Joshi 2024-02-25 10:34:47 +01:00 committed by GitHub
parent c513d51147
commit 277031cfb2
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
28 changed files with 729 additions and 1435 deletions

View file

@ -73,7 +73,6 @@ Available Types
telegram.keyboardbutton
telegram.keyboardbuttonpolltype
telegram.keyboardbuttonrequestchat
telegram.keyboardbuttonrequestuser
telegram.keyboardbuttonrequestusers
telegram.linkpreviewoptions
telegram.location
@ -115,7 +114,6 @@ Available Types
telegram.user
telegram.userchatboosts
telegram.userprofilephotos
telegram.usershared
telegram.usersshared
telegram.venue
telegram.video

View file

@ -1,6 +0,0 @@
KeyboardButtonRequestUser
=========================
.. autoclass:: telegram.KeyboardButtonRequestUser
:members:
:show-inheritance:

View file

@ -1,6 +0,0 @@
UserShared
==========
.. autoclass:: telegram.UserShared
:members:
:show-inheritance:

View file

@ -68,7 +68,7 @@
.. |rtm_aswr_deprecated| replace:: replacing this argument. PTB will automatically convert this argument to that one, but you should update your code to use the new argument.
.. |keyword_only_arg| replace:: In future versions, this argument will become a keyword-only argument.
.. |keyword_only_arg| replace:: This argument is now a keyword-only argument.
.. |text_html| replace:: The return value of this property is a best-effort approach. Unfortunately, it can not be guaranteed that sending a message with the returned string will render in the same way as the original message produces the same :attr:`~telegram.Message.entities`/:attr:`~telegram.Message.caption_entities` as the original message. For example, Telegram recommends that entities of type :attr:`~telegram.MessageEntity.BLOCKQUOTE` and :attr:`~telegram.MessageEntity.PRE` *should* start and end on a new line, but does not enforce this and leaves rendering decisions up to the clients.

View file

@ -130,7 +130,6 @@ __all__ = (
"KeyboardButton",
"KeyboardButtonPollType",
"KeyboardButtonRequestChat",
"KeyboardButtonRequestUser",
"KeyboardButtonRequestUsers",
"LabeledPrice",
"LinkPreviewOptions",
@ -198,7 +197,6 @@ __all__ = (
"User",
"UserChatBoosts",
"UserProfilePhotos",
"UserShared",
"UsersShared",
"Venue",
"Video",
@ -338,11 +336,7 @@ from ._inline.inputtextmessagecontent import InputTextMessageContent
from ._inline.inputvenuemessagecontent import InputVenueMessageContent
from ._keyboardbutton import KeyboardButton
from ._keyboardbuttonpolltype import KeyboardButtonPollType
from ._keyboardbuttonrequest import (
KeyboardButtonRequestChat,
KeyboardButtonRequestUser,
KeyboardButtonRequestUsers,
)
from ._keyboardbuttonrequest import KeyboardButtonRequestChat, KeyboardButtonRequestUsers
from ._linkpreviewoptions import LinkPreviewOptions
from ._loginurl import LoginUrl
from ._menubutton import MenuButton, MenuButtonCommands, MenuButtonDefault, MenuButtonWebApp
@ -397,7 +391,7 @@ from ._reply import ExternalReplyInfo, ReplyParameters, TextQuote
from ._replykeyboardmarkup import ReplyKeyboardMarkup
from ._replykeyboardremove import ReplyKeyboardRemove
from ._sentwebappmessage import SentWebAppMessage
from ._shared import ChatShared, UserShared, UsersShared
from ._shared import ChatShared, UsersShared
from ._story import Story
from ._switchinlinequerychosenchat import SwitchInlineQueryChosenChat
from ._telegramobject import TelegramObject

File diff suppressed because it is too large Load diff

View file

@ -209,11 +209,11 @@ class CallbackQuery(TelegramObject):
self,
text: str,
parse_mode: ODVInput[str] = DEFAULT_NONE,
disable_web_page_preview: ODVInput[bool] = DEFAULT_NONE,
reply_markup: Optional["InlineKeyboardMarkup"] = None,
entities: Optional[Sequence["MessageEntity"]] = None,
link_preview_options: ODVInput["LinkPreviewOptions"] = DEFAULT_NONE,
*,
disable_web_page_preview: Optional[bool] = None,
read_timeout: ODVInput[float] = DEFAULT_NONE,
write_timeout: ODVInput[float] = DEFAULT_NONE,
connect_timeout: ODVInput[float] = DEFAULT_NONE,
@ -808,13 +808,13 @@ class CallbackQuery(TelegramObject):
parse_mode: ODVInput[str] = DEFAULT_NONE,
caption_entities: Optional[Sequence["MessageEntity"]] = None,
disable_notification: ODVInput[bool] = DEFAULT_NONE,
reply_to_message_id: Optional[int] = None,
allow_sending_without_reply: ODVInput[bool] = DEFAULT_NONE,
reply_markup: Optional[ReplyMarkup] = None,
protect_content: ODVInput[bool] = DEFAULT_NONE,
message_thread_id: Optional[int] = None,
reply_parameters: Optional["ReplyParameters"] = None,
*,
allow_sending_without_reply: ODVInput[bool] = DEFAULT_NONE,
reply_to_message_id: Optional[int] = None,
read_timeout: ODVInput[float] = DEFAULT_NONE,
write_timeout: ODVInput[float] = DEFAULT_NONE,
connect_timeout: ODVInput[float] = DEFAULT_NONE,

View file

@ -1411,17 +1411,17 @@ class Chat(TelegramObject):
self,
text: str,
parse_mode: ODVInput[str] = DEFAULT_NONE,
disable_web_page_preview: ODVInput[bool] = DEFAULT_NONE,
disable_notification: ODVInput[bool] = DEFAULT_NONE,
reply_to_message_id: Optional[int] = None,
reply_markup: Optional[ReplyMarkup] = None,
allow_sending_without_reply: ODVInput[bool] = DEFAULT_NONE,
entities: Optional[Sequence["MessageEntity"]] = None,
protect_content: ODVInput[bool] = DEFAULT_NONE,
message_thread_id: Optional[int] = None,
link_preview_options: ODVInput["LinkPreviewOptions"] = DEFAULT_NONE,
reply_parameters: Optional["ReplyParameters"] = None,
*,
reply_to_message_id: Optional[int] = None,
allow_sending_without_reply: ODVInput[bool] = DEFAULT_NONE,
disable_web_page_preview: Optional[bool] = None,
read_timeout: ODVInput[float] = DEFAULT_NONE,
write_timeout: ODVInput[float] = DEFAULT_NONE,
connect_timeout: ODVInput[float] = DEFAULT_NONE,
@ -1529,12 +1529,12 @@ class Chat(TelegramObject):
Union["InputMediaAudio", "InputMediaDocument", "InputMediaPhoto", "InputMediaVideo"]
],
disable_notification: ODVInput[bool] = DEFAULT_NONE,
reply_to_message_id: Optional[int] = None,
allow_sending_without_reply: ODVInput[bool] = DEFAULT_NONE,
protect_content: ODVInput[bool] = DEFAULT_NONE,
message_thread_id: Optional[int] = None,
reply_parameters: Optional["ReplyParameters"] = None,
*,
reply_to_message_id: Optional[int] = None,
allow_sending_without_reply: ODVInput[bool] = DEFAULT_NONE,
read_timeout: ODVInput[float] = DEFAULT_NONE,
write_timeout: ODVInput[float] = DEFAULT_NONE,
connect_timeout: ODVInput[float] = DEFAULT_NONE,
@ -1614,16 +1614,16 @@ class Chat(TelegramObject):
photo: Union[FileInput, "PhotoSize"],
caption: Optional[str] = None,
disable_notification: ODVInput[bool] = DEFAULT_NONE,
reply_to_message_id: Optional[int] = None,
reply_markup: Optional[ReplyMarkup] = None,
parse_mode: ODVInput[str] = DEFAULT_NONE,
allow_sending_without_reply: ODVInput[bool] = DEFAULT_NONE,
caption_entities: Optional[Sequence["MessageEntity"]] = None,
protect_content: ODVInput[bool] = DEFAULT_NONE,
message_thread_id: Optional[int] = None,
has_spoiler: Optional[bool] = None,
reply_parameters: Optional["ReplyParameters"] = None,
*,
reply_to_message_id: Optional[int] = None,
allow_sending_without_reply: ODVInput[bool] = DEFAULT_NONE,
filename: Optional[str] = None,
read_timeout: ODVInput[float] = DEFAULT_NONE,
write_timeout: ODVInput[float] = DEFAULT_NONE,
@ -1669,14 +1669,14 @@ class Chat(TelegramObject):
first_name: Optional[str] = None,
last_name: Optional[str] = None,
disable_notification: ODVInput[bool] = DEFAULT_NONE,
reply_to_message_id: Optional[int] = None,
reply_markup: Optional[ReplyMarkup] = None,
vcard: Optional[str] = None,
allow_sending_without_reply: ODVInput[bool] = DEFAULT_NONE,
protect_content: ODVInput[bool] = DEFAULT_NONE,
message_thread_id: Optional[int] = None,
reply_parameters: Optional["ReplyParameters"] = None,
*,
reply_to_message_id: Optional[int] = None,
allow_sending_without_reply: ODVInput[bool] = DEFAULT_NONE,
contact: Optional["Contact"] = None,
read_timeout: ODVInput[float] = DEFAULT_NONE,
write_timeout: ODVInput[float] = DEFAULT_NONE,
@ -1723,16 +1723,16 @@ class Chat(TelegramObject):
title: Optional[str] = None,
caption: Optional[str] = None,
disable_notification: ODVInput[bool] = DEFAULT_NONE,
reply_to_message_id: Optional[int] = None,
reply_markup: Optional[ReplyMarkup] = None,
parse_mode: ODVInput[str] = DEFAULT_NONE,
allow_sending_without_reply: ODVInput[bool] = DEFAULT_NONE,
caption_entities: Optional[Sequence["MessageEntity"]] = None,
protect_content: ODVInput[bool] = DEFAULT_NONE,
message_thread_id: Optional[int] = None,
thumbnail: Optional[FileInput] = None,
reply_parameters: Optional["ReplyParameters"] = None,
*,
reply_to_message_id: Optional[int] = None,
allow_sending_without_reply: ODVInput[bool] = DEFAULT_NONE,
filename: Optional[str] = None,
read_timeout: ODVInput[float] = DEFAULT_NONE,
write_timeout: ODVInput[float] = DEFAULT_NONE,
@ -1780,17 +1780,17 @@ class Chat(TelegramObject):
document: Union[FileInput, "Document"],
caption: Optional[str] = None,
disable_notification: ODVInput[bool] = DEFAULT_NONE,
reply_to_message_id: Optional[int] = None,
reply_markup: Optional[ReplyMarkup] = None,
parse_mode: ODVInput[str] = DEFAULT_NONE,
disable_content_type_detection: Optional[bool] = None,
allow_sending_without_reply: ODVInput[bool] = DEFAULT_NONE,
caption_entities: Optional[Sequence["MessageEntity"]] = None,
protect_content: ODVInput[bool] = DEFAULT_NONE,
message_thread_id: Optional[int] = None,
thumbnail: Optional[FileInput] = None,
reply_parameters: Optional["ReplyParameters"] = None,
*,
reply_to_message_id: Optional[int] = None,
allow_sending_without_reply: ODVInput[bool] = DEFAULT_NONE,
filename: Optional[str] = None,
read_timeout: ODVInput[float] = DEFAULT_NONE,
write_timeout: ODVInput[float] = DEFAULT_NONE,
@ -1834,14 +1834,14 @@ class Chat(TelegramObject):
async def send_dice(
self,
disable_notification: ODVInput[bool] = DEFAULT_NONE,
reply_to_message_id: Optional[int] = None,
reply_markup: Optional[ReplyMarkup] = None,
emoji: Optional[str] = None,
allow_sending_without_reply: ODVInput[bool] = DEFAULT_NONE,
protect_content: ODVInput[bool] = DEFAULT_NONE,
message_thread_id: Optional[int] = None,
reply_parameters: Optional["ReplyParameters"] = None,
*,
reply_to_message_id: Optional[int] = None,
allow_sending_without_reply: ODVInput[bool] = DEFAULT_NONE,
read_timeout: ODVInput[float] = DEFAULT_NONE,
write_timeout: ODVInput[float] = DEFAULT_NONE,
connect_timeout: ODVInput[float] = DEFAULT_NONE,
@ -1879,13 +1879,13 @@ class Chat(TelegramObject):
self,
game_short_name: str,
disable_notification: ODVInput[bool] = DEFAULT_NONE,
reply_to_message_id: Optional[int] = None,
reply_markup: Optional["InlineKeyboardMarkup"] = None,
allow_sending_without_reply: ODVInput[bool] = DEFAULT_NONE,
protect_content: ODVInput[bool] = DEFAULT_NONE,
message_thread_id: Optional[int] = None,
reply_parameters: Optional["ReplyParameters"] = None,
*,
reply_to_message_id: Optional[int] = None,
allow_sending_without_reply: ODVInput[bool] = DEFAULT_NONE,
read_timeout: ODVInput[float] = DEFAULT_NONE,
write_timeout: ODVInput[float] = DEFAULT_NONE,
connect_timeout: ODVInput[float] = DEFAULT_NONE,
@ -1938,18 +1938,18 @@ class Chat(TelegramObject):
need_shipping_address: Optional[bool] = None,
is_flexible: Optional[bool] = None,
disable_notification: ODVInput[bool] = DEFAULT_NONE,
reply_to_message_id: Optional[int] = None,
reply_markup: Optional["InlineKeyboardMarkup"] = None,
provider_data: Optional[Union[str, object]] = None,
send_phone_number_to_provider: Optional[bool] = None,
send_email_to_provider: Optional[bool] = None,
allow_sending_without_reply: ODVInput[bool] = DEFAULT_NONE,
max_tip_amount: Optional[int] = None,
suggested_tip_amounts: Optional[Sequence[int]] = None,
protect_content: ODVInput[bool] = DEFAULT_NONE,
message_thread_id: Optional[int] = None,
reply_parameters: Optional["ReplyParameters"] = None,
*,
reply_to_message_id: Optional[int] = None,
allow_sending_without_reply: ODVInput[bool] = DEFAULT_NONE,
read_timeout: ODVInput[float] = DEFAULT_NONE,
write_timeout: ODVInput[float] = DEFAULT_NONE,
connect_timeout: ODVInput[float] = DEFAULT_NONE,
@ -2018,17 +2018,17 @@ class Chat(TelegramObject):
latitude: Optional[float] = None,
longitude: Optional[float] = None,
disable_notification: ODVInput[bool] = DEFAULT_NONE,
reply_to_message_id: Optional[int] = None,
reply_markup: Optional[ReplyMarkup] = None,
live_period: Optional[int] = None,
horizontal_accuracy: Optional[float] = None,
heading: Optional[int] = None,
proximity_alert_radius: Optional[int] = None,
allow_sending_without_reply: ODVInput[bool] = DEFAULT_NONE,
protect_content: ODVInput[bool] = DEFAULT_NONE,
message_thread_id: Optional[int] = None,
reply_parameters: Optional["ReplyParameters"] = None,
*,
reply_to_message_id: Optional[int] = None,
allow_sending_without_reply: ODVInput[bool] = DEFAULT_NONE,
location: Optional["Location"] = None,
read_timeout: ODVInput[float] = DEFAULT_NONE,
write_timeout: ODVInput[float] = DEFAULT_NONE,
@ -2078,9 +2078,7 @@ class Chat(TelegramObject):
caption: Optional[str] = None,
parse_mode: ODVInput[str] = DEFAULT_NONE,
disable_notification: ODVInput[bool] = DEFAULT_NONE,
reply_to_message_id: Optional[int] = None,
reply_markup: Optional[ReplyMarkup] = None,
allow_sending_without_reply: ODVInput[bool] = DEFAULT_NONE,
caption_entities: Optional[Sequence["MessageEntity"]] = None,
protect_content: ODVInput[bool] = DEFAULT_NONE,
message_thread_id: Optional[int] = None,
@ -2088,6 +2086,8 @@ class Chat(TelegramObject):
thumbnail: Optional[FileInput] = None,
reply_parameters: Optional["ReplyParameters"] = None,
*,
reply_to_message_id: Optional[int] = None,
allow_sending_without_reply: ODVInput[bool] = DEFAULT_NONE,
filename: Optional[str] = None,
read_timeout: ODVInput[float] = DEFAULT_NONE,
write_timeout: ODVInput[float] = DEFAULT_NONE,
@ -2135,14 +2135,14 @@ class Chat(TelegramObject):
self,
sticker: Union[FileInput, "Sticker"],
disable_notification: ODVInput[bool] = DEFAULT_NONE,
reply_to_message_id: Optional[int] = None,
reply_markup: Optional[ReplyMarkup] = None,
allow_sending_without_reply: ODVInput[bool] = DEFAULT_NONE,
protect_content: ODVInput[bool] = DEFAULT_NONE,
message_thread_id: Optional[int] = None,
emoji: Optional[str] = None,
reply_parameters: Optional["ReplyParameters"] = None,
*,
reply_to_message_id: Optional[int] = None,
allow_sending_without_reply: ODVInput[bool] = DEFAULT_NONE,
read_timeout: ODVInput[float] = DEFAULT_NONE,
write_timeout: ODVInput[float] = DEFAULT_NONE,
connect_timeout: ODVInput[float] = DEFAULT_NONE,
@ -2185,16 +2185,16 @@ class Chat(TelegramObject):
address: Optional[str] = None,
foursquare_id: Optional[str] = None,
disable_notification: ODVInput[bool] = DEFAULT_NONE,
reply_to_message_id: Optional[int] = None,
reply_markup: Optional[ReplyMarkup] = None,
foursquare_type: Optional[str] = None,
google_place_id: Optional[str] = None,
google_place_type: Optional[str] = None,
allow_sending_without_reply: ODVInput[bool] = DEFAULT_NONE,
protect_content: ODVInput[bool] = DEFAULT_NONE,
message_thread_id: Optional[int] = None,
reply_parameters: Optional["ReplyParameters"] = None,
*,
reply_to_message_id: Optional[int] = None,
allow_sending_without_reply: ODVInput[bool] = DEFAULT_NONE,
venue: Optional["Venue"] = None,
read_timeout: ODVInput[float] = DEFAULT_NONE,
write_timeout: ODVInput[float] = DEFAULT_NONE,
@ -2243,13 +2243,11 @@ class Chat(TelegramObject):
duration: Optional[int] = None,
caption: Optional[str] = None,
disable_notification: ODVInput[bool] = DEFAULT_NONE,
reply_to_message_id: Optional[int] = None,
reply_markup: Optional[ReplyMarkup] = None,
width: Optional[int] = None,
height: Optional[int] = None,
parse_mode: ODVInput[str] = DEFAULT_NONE,
supports_streaming: Optional[bool] = None,
allow_sending_without_reply: ODVInput[bool] = DEFAULT_NONE,
caption_entities: Optional[Sequence["MessageEntity"]] = None,
protect_content: ODVInput[bool] = DEFAULT_NONE,
message_thread_id: Optional[int] = None,
@ -2257,6 +2255,8 @@ class Chat(TelegramObject):
thumbnail: Optional[FileInput] = None,
reply_parameters: Optional["ReplyParameters"] = None,
*,
reply_to_message_id: Optional[int] = None,
allow_sending_without_reply: ODVInput[bool] = DEFAULT_NONE,
filename: Optional[str] = None,
read_timeout: ODVInput[float] = DEFAULT_NONE,
write_timeout: ODVInput[float] = DEFAULT_NONE,
@ -2307,14 +2307,14 @@ class Chat(TelegramObject):
duration: Optional[int] = None,
length: Optional[int] = None,
disable_notification: ODVInput[bool] = DEFAULT_NONE,
reply_to_message_id: Optional[int] = None,
reply_markup: Optional[ReplyMarkup] = None,
allow_sending_without_reply: ODVInput[bool] = DEFAULT_NONE,
protect_content: ODVInput[bool] = DEFAULT_NONE,
message_thread_id: Optional[int] = None,
thumbnail: Optional[FileInput] = None,
reply_parameters: Optional["ReplyParameters"] = None,
*,
reply_to_message_id: Optional[int] = None,
allow_sending_without_reply: ODVInput[bool] = DEFAULT_NONE,
filename: Optional[str] = None,
read_timeout: ODVInput[float] = DEFAULT_NONE,
write_timeout: ODVInput[float] = DEFAULT_NONE,
@ -2359,15 +2359,15 @@ class Chat(TelegramObject):
duration: Optional[int] = None,
caption: Optional[str] = None,
disable_notification: ODVInput[bool] = DEFAULT_NONE,
reply_to_message_id: Optional[int] = None,
reply_markup: Optional[ReplyMarkup] = None,
parse_mode: ODVInput[str] = DEFAULT_NONE,
allow_sending_without_reply: ODVInput[bool] = DEFAULT_NONE,
caption_entities: Optional[Sequence["MessageEntity"]] = None,
protect_content: ODVInput[bool] = DEFAULT_NONE,
message_thread_id: Optional[int] = None,
reply_parameters: Optional["ReplyParameters"] = None,
*,
reply_to_message_id: Optional[int] = None,
allow_sending_without_reply: ODVInput[bool] = DEFAULT_NONE,
filename: Optional[str] = None,
read_timeout: ODVInput[float] = DEFAULT_NONE,
write_timeout: ODVInput[float] = DEFAULT_NONE,
@ -2417,18 +2417,18 @@ class Chat(TelegramObject):
correct_option_id: Optional[CorrectOptionID] = None,
is_closed: Optional[bool] = None,
disable_notification: ODVInput[bool] = DEFAULT_NONE,
reply_to_message_id: Optional[int] = None,
reply_markup: Optional[ReplyMarkup] = None,
explanation: Optional[str] = None,
explanation_parse_mode: ODVInput[str] = DEFAULT_NONE,
open_period: Optional[int] = None,
close_date: Optional[Union[int, datetime]] = None,
allow_sending_without_reply: ODVInput[bool] = DEFAULT_NONE,
explanation_entities: Optional[Sequence["MessageEntity"]] = None,
protect_content: ODVInput[bool] = DEFAULT_NONE,
message_thread_id: Optional[int] = None,
reply_parameters: Optional["ReplyParameters"] = None,
*,
reply_to_message_id: Optional[int] = None,
allow_sending_without_reply: ODVInput[bool] = DEFAULT_NONE,
read_timeout: ODVInput[float] = DEFAULT_NONE,
write_timeout: ODVInput[float] = DEFAULT_NONE,
connect_timeout: ODVInput[float] = DEFAULT_NONE,
@ -2481,13 +2481,13 @@ class Chat(TelegramObject):
parse_mode: ODVInput[str] = DEFAULT_NONE,
caption_entities: Optional[Sequence["MessageEntity"]] = None,
disable_notification: ODVInput[bool] = DEFAULT_NONE,
reply_to_message_id: Optional[int] = None,
allow_sending_without_reply: ODVInput[bool] = DEFAULT_NONE,
reply_markup: Optional[ReplyMarkup] = None,
protect_content: ODVInput[bool] = DEFAULT_NONE,
message_thread_id: Optional[int] = None,
reply_parameters: Optional["ReplyParameters"] = None,
*,
reply_to_message_id: Optional[int] = None,
allow_sending_without_reply: ODVInput[bool] = DEFAULT_NONE,
read_timeout: ODVInput[float] = DEFAULT_NONE,
write_timeout: ODVInput[float] = DEFAULT_NONE,
connect_timeout: ODVInput[float] = DEFAULT_NONE,
@ -2535,13 +2535,13 @@ class Chat(TelegramObject):
parse_mode: ODVInput[str] = DEFAULT_NONE,
caption_entities: Optional[Sequence["MessageEntity"]] = None,
disable_notification: ODVInput[bool] = DEFAULT_NONE,
reply_to_message_id: Optional[int] = None,
allow_sending_without_reply: ODVInput[bool] = DEFAULT_NONE,
reply_markup: Optional[ReplyMarkup] = None,
protect_content: ODVInput[bool] = DEFAULT_NONE,
message_thread_id: Optional[int] = None,
reply_parameters: Optional["ReplyParameters"] = None,
*,
reply_to_message_id: Optional[int] = None,
allow_sending_without_reply: ODVInput[bool] = DEFAULT_NONE,
read_timeout: ODVInput[float] = DEFAULT_NONE,
write_timeout: ODVInput[float] = DEFAULT_NONE,
connect_timeout: ODVInput[float] = DEFAULT_NONE,

View file

@ -21,13 +21,9 @@ from typing import TYPE_CHECKING, Optional, Sequence, Tuple
from telegram._inline.inputmessagecontent import InputMessageContent
from telegram._messageentity import MessageEntity
from telegram._utils.argumentparsing import parse_sequence_arg
from telegram._utils.defaultvalue import DEFAULT_NONE, DefaultValue
from telegram._utils.argumentparsing import parse_lpo_and_dwpp, parse_sequence_arg
from telegram._utils.defaultvalue import DEFAULT_NONE
from telegram._utils.types import JSONDict, ODVInput
from telegram._utils.warnings_transition import (
warn_about_deprecated_attr_in_property,
warn_for_link_preview_options,
)
if TYPE_CHECKING:
from telegram._linkpreviewoptions import LinkPreviewOptions
@ -54,22 +50,24 @@ class InputTextMessageContent(InputMessageContent):
.. versionchanged:: 20.0
|sequenceclassargs|
link_preview_options (:obj:`LinkPreviewOptions`, optional): Link preview generation
options for the message. Mutually exclusive with
:paramref:`disable_web_page_preview`.
.. versionadded:: 20.8
Keyword Args:
disable_web_page_preview (:obj:`bool`, optional): Disables link previews for links in the
sent message. Mutually exclusive with :paramref:`link_preview_options`.
sent message. Convenience parameter for setting :paramref:`link_preview_options`.
Mutually exclusive with :paramref:`link_preview_options`.
.. versionchanged:: 20.8
Bot API 7.0 introduced :paramref:`link_preview_options` replacing this
argument. PTB will automatically convert this argument to that one, but
for advanced options, please use :paramref:`link_preview_options` directly.
.. deprecated:: 20.8
In future versions, this argument will become keyword only.
link_preview_options (:obj:`LinkPreviewOptions`, optional): Link preview generation
options for the message. Mutually exclusive with
:paramref:`disable_web_page_preview`.
.. versionadded:: 20.8
.. versionchanged:: NEXT.VERSION
|keyword_only_arg|
Attributes:
message_text (:obj:`str`): Text of the message to be sent,
@ -84,8 +82,7 @@ class InputTextMessageContent(InputMessageContent):
* |tupleclassattrs|
* |alwaystuple|
link_preview_options (:obj:`LinkPreviewOptions`): Optional. Link preview generation
options for the message. Mutually exclusive with
:attr:`disable_web_page_preview`.
options for the message.
.. versionadded:: 20.8
@ -97,10 +94,10 @@ class InputTextMessageContent(InputMessageContent):
self,
message_text: str,
parse_mode: ODVInput[str] = DEFAULT_NONE,
disable_web_page_preview: ODVInput[bool] = DEFAULT_NONE,
entities: Optional[Sequence[MessageEntity]] = None,
link_preview_options: ODVInput["LinkPreviewOptions"] = DEFAULT_NONE,
*,
disable_web_page_preview: Optional[bool] = None,
api_kwargs: Optional[JSONDict] = None,
):
super().__init__(api_kwargs=api_kwargs)
@ -111,27 +108,8 @@ class InputTextMessageContent(InputMessageContent):
# Optionals
self.parse_mode: ODVInput[str] = parse_mode
self.entities: Tuple[MessageEntity, ...] = parse_sequence_arg(entities)
self.link_preview_options: ODVInput["LinkPreviewOptions"] = (
warn_for_link_preview_options(disable_web_page_preview, link_preview_options)
self.link_preview_options: ODVInput["LinkPreviewOptions"] = parse_lpo_and_dwpp(
disable_web_page_preview, link_preview_options
)
self._id_attrs = (self.message_text,)
@property
def disable_web_page_preview(self) -> Optional[bool]:
"""Optional[:obj:`bool`]: Disables link previews for links in the sent message.
.. deprecated:: 20.8
"""
warn_about_deprecated_attr_in_property(
deprecated_attr_name="disable_web_page_preview",
new_attr_name="link_preview_options",
bot_api_version="7.0",
stacklevel=2,
)
if (
isinstance(self.link_preview_options, DefaultValue)
or self.link_preview_options is None
):
return None
return bool(self.link_preview_options.is_disabled)

View file

@ -18,20 +18,12 @@
# along with this program. If not, see [http://www.gnu.org/licenses/].
"""This module contains an object that represents a Telegram KeyboardButton."""
from typing import TYPE_CHECKING, Optional, Union
from typing import TYPE_CHECKING, Optional
from telegram._keyboardbuttonpolltype import KeyboardButtonPollType
from telegram._keyboardbuttonrequest import (
KeyboardButtonRequestChat,
KeyboardButtonRequestUser,
KeyboardButtonRequestUsers,
)
from telegram._keyboardbuttonrequest import KeyboardButtonRequestChat, KeyboardButtonRequestUsers
from telegram._telegramobject import TelegramObject
from telegram._utils.types import JSONDict
from telegram._utils.warnings_transition import (
warn_about_deprecated_arg_return_new_arg,
warn_about_deprecated_attr_in_property,
)
from telegram._webappinfo import WebAppInfo
if TYPE_CHECKING:
@ -60,6 +52,8 @@ class KeyboardButton(TelegramObject):
versions released after 3 February, 2023. Older clients will display unsupported
message.
.. versionchanged:: NEXT.VERSION
Removed deprecated argument and attribute ``request_user``.
.. versionchanged:: 20.0
:attr:`web_app` is considered as well when comparing objects of this type in terms of
equality.
@ -83,17 +77,10 @@ class KeyboardButton(TelegramObject):
Available in private chats only.
.. versionadded:: 20.0
request_user (:class:`KeyboardButtonRequestUser` | :class:`KeyboardButtonRequestUsers`, \
optional): Alias for
:attr:`request_users`.
.. versionadded:: 20.1
.. deprecated:: 20.8
Bot API 7.0 deprecates this argument in favor of ref`request_users`.
request_users (:class:`KeyboardButtonRequestUsers`, optional): If specified, pressing the
button will open a list of suitable users. Tapping on any user will send its
identifier to the bot in a :attr:`telegram.Message.user_shared` service message.
identifier to the bot in a :attr:`telegram.Message.users_shared` service message.
Available in private chats only.
.. versionadded:: 20.8
@ -121,7 +108,7 @@ class KeyboardButton(TelegramObject):
.. versionadded:: 20.0
request_users (:class:`KeyboardButtonRequestUsers`): Optional. If specified, pressing the
button will open a list of suitable users. Tapping on any user will send its
identifier to the bot in a :attr:`telegram.Message.user_shared` service message.
identifier to the bot in a :attr:`telegram.Message.users_shared` service message.
Available in private chats only.
.. versionadded:: 20.8
@ -150,9 +137,6 @@ class KeyboardButton(TelegramObject):
request_location: Optional[bool] = None,
request_poll: Optional[KeyboardButtonPollType] = None,
web_app: Optional[WebAppInfo] = None,
request_user: Optional[
Union[KeyboardButtonRequestUsers, KeyboardButtonRequestUser]
] = None,
request_chat: Optional[KeyboardButtonRequestChat] = None,
request_users: Optional[KeyboardButtonRequestUsers] = None,
*,
@ -167,15 +151,7 @@ class KeyboardButton(TelegramObject):
self.request_location: Optional[bool] = request_location
self.request_poll: Optional[KeyboardButtonPollType] = request_poll
self.web_app: Optional[WebAppInfo] = web_app
self.request_users: Optional[KeyboardButtonRequestUsers] = (
warn_about_deprecated_arg_return_new_arg(
deprecated_arg=request_user,
new_arg=request_users,
deprecated_arg_name="request_user",
new_arg_name="request_users",
bot_api_version="7.0",
)
)
self.request_users: Optional[KeyboardButtonRequestUsers] = request_users
self.request_chat: Optional[KeyboardButtonRequestChat] = request_chat
self._id_attrs = (
@ -190,21 +166,6 @@ class KeyboardButton(TelegramObject):
self._freeze()
@property
def request_user(self) -> Optional[KeyboardButtonRequestUsers]:
"""Optional[:class:`KeyboardButtonRequestUsers`]: Alias for :attr:`request_users`.
.. versionadded:: 20.1
.. deprecated:: 20.8
Bot API 7.0 deprecates this attribute in favor of :attr:`request_users`.
"""
warn_about_deprecated_attr_in_property(
deprecated_attr_name="request_user",
new_attr_name="request_users",
bot_api_version="7.0",
)
return self.request_users
@classmethod
def de_json(cls, data: Optional[JSONDict], bot: "Bot") -> Optional["KeyboardButton"]:
"""See :meth:`telegram.TelegramObject.de_json`."""
@ -218,4 +179,10 @@ class KeyboardButton(TelegramObject):
data["request_chat"] = KeyboardButtonRequestChat.de_json(data.get("request_chat"), bot)
data["web_app"] = WebAppInfo.de_json(data.get("web_app"), bot)
return super().de_json(data=data, bot=bot)
api_kwargs = {}
# This is a deprecated field that TG still returns for backwards compatibility
# Let's filter it out to speed up the de-json process
if request_user := data.get("request_user"):
api_kwargs = {"request_user": request_user}
return super()._de_json(data=data, bot=bot, api_kwargs=api_kwargs)

View file

@ -22,9 +22,6 @@ from typing import TYPE_CHECKING, Optional
from telegram._chatadministratorrights import ChatAdministratorRights
from telegram._telegramobject import TelegramObject
from telegram._utils.types import JSONDict
from telegram._utils.warnings import warn
from telegram._utils.warnings_transition import build_deprecation_warning_message
from telegram.warnings import PTBDeprecationWarning
if TYPE_CHECKING:
from telegram import Bot
@ -42,7 +39,7 @@ class KeyboardButtonRequestUsers(TelegramObject):
<https://core.telegram.org/bots/features#chat-and-user-selection>`_
.. versionadded:: 20.8
This class was previously named :class:`KeyboardButtonRequestUser`.
This class was previously named ``KeyboardButtonRequestUser``.
Args:
request_id (:obj:`int`): Signed 32-bit identifier of the request, which will be received
@ -106,49 +103,6 @@ class KeyboardButtonRequestUsers(TelegramObject):
self._freeze()
class KeyboardButtonRequestUser(KeyboardButtonRequestUsers):
"""Alias for :class:`KeyboardButtonRequestUsers`, kept for backward compatibility.
.. versionadded:: 20.1
.. deprecated:: 20.8
Use :class:`KeyboardButtonRequestUsers` instead.
"""
__slots__ = ()
def __init__(
self,
request_id: int,
user_is_bot: Optional[bool] = None,
user_is_premium: Optional[bool] = None,
max_quantity: Optional[int] = None,
*,
api_kwargs: Optional[JSONDict] = None, # skipcq: PYL-W0622
):
super().__init__(
request_id=request_id,
user_is_bot=user_is_bot,
user_is_premium=user_is_premium,
max_quantity=max_quantity,
api_kwargs=api_kwargs,
)
warn(
build_deprecation_warning_message(
deprecated_name="KeyboardButtonRequestUser",
new_name="KeyboardButtonRequestUsers",
object_type="class",
bot_api_version="7.0",
),
PTBDeprecationWarning,
stacklevel=2,
)
self._freeze()
class KeyboardButtonRequestChat(TelegramObject):
"""This object defines the criteria used to request a suitable chat. The identifier of the
selected user will be shared with the bot when the corresponding button is pressed.

View file

@ -55,7 +55,7 @@ from telegram._payment.successfulpayment import SuccessfulPayment
from telegram._poll import Poll
from telegram._proximityalerttriggered import ProximityAlertTriggered
from telegram._reply import ReplyParameters
from telegram._shared import ChatShared, UserShared, UsersShared
from telegram._shared import ChatShared, UsersShared
from telegram._story import Story
from telegram._telegramobject import TelegramObject
from telegram._user import User
@ -71,10 +71,6 @@ from telegram._utils.types import (
ReplyMarkup,
)
from telegram._utils.warnings import warn
from telegram._utils.warnings_transition import (
build_deprecation_warning_message,
warn_about_deprecated_attr_in_property,
)
from telegram._videochat import (
VideoChatEnded,
VideoChatParticipantsInvited,
@ -124,6 +120,9 @@ class MaybeInaccessibleMessage(TelegramObject):
Objects of this class are comparable in terms of equality. Two objects of this class are
considered equal, if their :attr:`message_id` and :attr:`chat` are equal
.. versionchanged:: NEXT.VERSION
``__bool__`` is no longer overriden and defaults to Pythons standard implementation.
.. versionadded:: 20.8
Args:
@ -162,51 +161,6 @@ class MaybeInaccessibleMessage(TelegramObject):
self._freeze()
def __bool__(self) -> bool:
"""Overrides :meth:`object.__bool__` to return the value of :attr:`is_accessible`.
This is intended to ease migration to Bot API 7.0, as this allows checks like
.. code-block:: python
if message.pinned_message:
...
to work as before, when ``message.pinned_message`` was :obj:`None`. Note that this does not
help with check like
.. code-block:: python
if message.pinned_message is None:
...
for cases where ``message.pinned_message`` is now no longer :obj:`None`.
Tip:
Since objects that can only be of type :class:`~telegram.Message` or :obj:`None` are
not affected by this change, :meth:`Message.__bool__` is not overridden and will
continue to work as before.
.. versionadded:: 20.8
.. deprecated:: 20.8
This behavior is introduced only temporarily to ease migration to Bot API 7.0. It will
be removed along with other functionality deprecated by Bot API 7.0.
"""
# Once we remove this method, also remove `Message.__bool__`.
warn(
category=PTBDeprecationWarning,
message=(
"You probably see this warning "
"because you wrote `if callback_query.message` or `if message.pinned_message` in "
"your code. This is not the supported way of checking the existence of a message "
"as of API 7.0. Please use `if message.is_accessible` or `if isinstance(message, "
"Message)` instead. `if message is None` may be suitable for specific use cases "
f"as well.\n`{self.__class__.__name__}.__bool__` will be reverted to Pythons "
f"default implementation in future versions."
),
stacklevel=2,
)
return self.is_accessible
@property
def is_accessible(self) -> bool:
"""Convenience attribute. :obj:`True`, if the date is not 0 in Unix time.
@ -218,7 +172,9 @@ class MaybeInaccessibleMessage(TelegramObject):
return self.date != ZERO_DATE
@classmethod
def de_json(cls, data: Optional[JSONDict], bot: "Bot") -> Optional["MaybeInaccessibleMessage"]:
def _de_json(
cls, data: Optional[JSONDict], bot: "Bot", api_kwargs: Optional[JSONDict] = None
) -> Optional["MaybeInaccessibleMessage"]:
"""See :meth:`telegram.TelegramObject.de_json`."""
data = cls._parse_data(data)
@ -240,7 +196,7 @@ class MaybeInaccessibleMessage(TelegramObject):
data["date"] = from_timestamp(data["date"], tzinfo=loc_tzinfo)
data["chat"] = Chat.de_json(data.get("chat"), bot)
return super().de_json(data=data, bot=bot)
return super()._de_json(data=data, bot=bot)
class InaccessibleMessage(MaybeInaccessibleMessage):
@ -287,6 +243,11 @@ class Message(MaybeInaccessibleMessage):
Note:
In Python :keyword:`from` is a reserved word. Use :paramref:`from_user` instead.
.. versionchanged:: NEXT.VERSION
Removed deprecated arguments and attributes ``user_shared``, ``forward_from``,
``forward_from_chat``, ``forward_from_message_id``, ``forward_signature``,
``forward_sender_name`` and ``forward_date``.
.. versionchanged:: 20.8
* This class is now a subclass of :class:`telegram.MaybeInaccessibleMessage`.
* The :paramref:`pinned_message` now can be either class:`telegram.Message` or
@ -323,39 +284,6 @@ class Message(MaybeInaccessibleMessage):
.. versionchanged:: 20.3
|datetime_localization|
chat (:class:`telegram.Chat`): Conversation the message belongs to.
forward_from (:class:`telegram.User`, optional): For forwarded messages, sender of
the original message.
.. deprecated:: 20.8
Bot API 7.0 deprecates :paramref:`forward_from` in favor of
:paramref:`forward_origin`.
forward_from_chat (:class:`telegram.Chat`, optional): For messages forwarded from channels
or from anonymous administrators, information about the original sender chat.
.. deprecated:: 20.8
Bot API 7.0 deprecates :paramref:`forward_from_chat` in favor of
:paramref:`forward_origin`.
forward_from_message_id (:obj:`int`, optional): For forwarded channel posts, identifier of
the original message in the channel.
.. deprecated:: 20.8
Bot API 7.0 deprecates :paramref:`forward_from_message_id` in favor of
:paramref:`forward_origin`.
forward_sender_name (:obj:`str`, optional): Sender's name for messages forwarded from
users who disallow adding a link to their account in forwarded messages.
.. deprecated:: 20.8
Bot API 7.0 deprecates :paramref:`forward_sender_name` in favor of
:paramref:`forward_origin`.
forward_date (:class:`datetime.datetime`, optional): For forwarded messages, date the
original message was sent in Unix time. Converted to :class:`datetime.datetime`.
.. versionchanged:: 20.3
|datetime_localization|
.. deprecated:: 20.8
Bot API 7.0 deprecates :paramref:`forward_date` in favor of
:paramref:`forward_origin`.
is_automatic_forward (:obj:`bool`, optional): :obj:`True`, if the message is a channel
post that was automatically forwarded to the connected discussion group.
@ -481,12 +409,6 @@ class Message(MaybeInaccessibleMessage):
message about a successful payment, information about the payment.
connected_website (:obj:`str`, optional): The domain name of the website on which the user
has logged in.
forward_signature (:obj:`str`, optional): For messages forwarded from channels, signature
of the post author if present.
.. deprecated:: 20.8
Bot API 7.0 deprecates :paramref:`forward_signature` in favor of
:paramref:`forward_origin`.
author_signature (:obj:`str`, optional): Signature of the post author for messages in
channels, or the custom title of an anonymous group administrator.
passport_data (:class:`telegram.PassportData`, optional): Telegram Passport data.
@ -563,12 +485,6 @@ class Message(MaybeInaccessibleMessage):
by a spoiler animation.
.. versionadded:: 20.0
user_shared (:class:`telegram.UserShared`, optional): Service message: a user was shared
with the bot.
.. versionadded:: 20.1
.. deprecated:: 20.8
Bot API 7.0 deprecates :paramref:`user_shared` in favor of :paramref:`users_shared`.
users_shared (:class:`telegram.UsersShared`, optional): Service message: users were shared
with the bot
@ -888,13 +804,6 @@ class Message(MaybeInaccessibleMessage):
# fmt: on
__slots__ = (
"_effective_attachment",
"_forward_date",
"_forward_from",
"_forward_from_chat",
"_forward_from_message_id",
"_forward_sender_name",
"_forward_signature",
"_user_shared",
"animation",
"audio",
"author_signature",
@ -974,10 +883,6 @@ class Message(MaybeInaccessibleMessage):
date: datetime.datetime,
chat: Chat,
from_user: Optional[User] = None,
forward_from: Optional[User] = None,
forward_from_chat: Optional[Chat] = None,
forward_from_message_id: Optional[int] = None,
forward_date: Optional[datetime.datetime] = None,
reply_to_message: Optional["Message"] = None,
edit_date: Optional[datetime.datetime] = None,
text: Optional[str] = None,
@ -1008,14 +913,12 @@ class Message(MaybeInaccessibleMessage):
pinned_message: Optional[MaybeInaccessibleMessage] = None,
invoice: Optional[Invoice] = None,
successful_payment: Optional[SuccessfulPayment] = None,
forward_signature: Optional[str] = None,
author_signature: Optional[str] = None,
media_group_id: Optional[str] = None,
connected_website: Optional[str] = None,
animation: Optional[Animation] = None,
passport_data: Optional[PassportData] = None,
poll: Optional[Poll] = None,
forward_sender_name: Optional[str] = None,
reply_markup: Optional[InlineKeyboardMarkup] = None,
dice: Optional[Dice] = None,
via_bot: Optional[User] = None,
@ -1039,7 +942,6 @@ class Message(MaybeInaccessibleMessage):
general_forum_topic_unhidden: Optional[GeneralForumTopicUnhidden] = None,
write_access_allowed: Optional[WriteAccessAllowed] = None,
has_media_spoiler: Optional[bool] = None,
user_shared: Optional[UserShared] = None,
chat_shared: Optional[ChatShared] = None,
story: Optional[Story] = None,
giveaway: Optional["Giveaway"] = None,
@ -1056,49 +958,6 @@ class Message(MaybeInaccessibleMessage):
):
super().__init__(chat=chat, message_id=message_id, date=date, api_kwargs=api_kwargs)
if user_shared:
warn(
build_deprecation_warning_message(
deprecated_name="user_shared",
new_name="users_shared",
object_type="parameter",
bot_api_version="7.0",
),
PTBDeprecationWarning,
stacklevel=2,
)
if any(
(
forward_from,
forward_from_chat,
forward_from_message_id,
forward_signature,
forward_sender_name,
forward_date,
)
):
if forward_from:
_warn_param = "forward_from"
elif forward_from_chat:
_warn_param = "forward_from_chat"
elif forward_from_message_id:
_warn_param = "forward_from_message_id"
elif forward_signature:
_warn_param = "forward_signature"
elif forward_sender_name:
_warn_param = "forward_sender_name"
else:
_warn_param = "forward_date"
warn(
f"The information about parameter '{_warn_param}' was transferred to "
"'forward_origin' in Bot API 7.0. We recommend using 'forward_origin' instead of "
f"'{_warn_param}'",
PTBDeprecationWarning,
stacklevel=2,
)
with self._unfrozen():
# Required
self.message_id: int = message_id
@ -1107,9 +966,6 @@ class Message(MaybeInaccessibleMessage):
self.sender_chat: Optional[Chat] = sender_chat
self.date: datetime.datetime = date
self.chat: Chat = chat
self._forward_from: Optional[User] = forward_from
self._forward_from_chat: Optional[Chat] = forward_from_chat
self._forward_date: Optional[datetime.datetime] = forward_date
self.is_automatic_forward: Optional[bool] = is_automatic_forward
self.reply_to_message: Optional[Message] = reply_to_message
self.edit_date: Optional[datetime.datetime] = edit_date
@ -1143,12 +999,9 @@ class Message(MaybeInaccessibleMessage):
message_auto_delete_timer_changed
)
self.pinned_message: Optional[MaybeInaccessibleMessage] = pinned_message
self._forward_from_message_id: Optional[int] = forward_from_message_id
self.invoice: Optional[Invoice] = invoice
self.successful_payment: Optional[SuccessfulPayment] = successful_payment
self.connected_website: Optional[str] = connected_website
self._forward_signature: Optional[str] = forward_signature
self._forward_sender_name: Optional[str] = forward_sender_name
self.author_signature: Optional[str] = author_signature
self.media_group_id: Optional[str] = media_group_id
self.animation: Optional[Animation] = animation
@ -1181,7 +1034,6 @@ class Message(MaybeInaccessibleMessage):
)
self.write_access_allowed: Optional[WriteAccessAllowed] = write_access_allowed
self.has_media_spoiler: Optional[bool] = has_media_spoiler
self._user_shared: Optional[UserShared] = user_shared
self.users_shared: Optional[UsersShared] = users_shared
self.chat_shared: Optional[ChatShared] = chat_shared
self.story: Optional[Story] = story
@ -1198,132 +1050,6 @@ class Message(MaybeInaccessibleMessage):
self._id_attrs = (self.message_id, self.chat)
def __bool__(self) -> bool:
"""Overrides :meth:`telegram.MaybeInaccessibleMessage.__bool__` to use Pythons
default implementation of :meth:`object.__bool__` instead.
Tip:
The current behavior is the same as before the introduction of
:class:`telegram.MaybeInaccessibleMessage`. This documentation is relevant only until
:meth:`telegram.MaybeInaccessibleMessage.__bool__` is removed.
"""
return True
@property
def user_shared(self) -> Optional[UserShared]:
""":class:`telegram.UserShared`: Optional. Service message. A user was shared with the
bot.
Hint:
In case a single user was shared, :attr:`user_shared` will be present in addition to
:attr:`users_shared`. If multiple users where shared, only :attr:`users_shared` will
be present. However, this behavior is not documented and may be changed by Telegram.
.. versionadded:: 20.1
.. deprecated:: 20.8
Bot API 7.0 deprecates :attr:`user_shared` in favor of :attr:`users_shared`.
"""
warn_about_deprecated_attr_in_property(
deprecated_attr_name="user_shared",
new_attr_name="users_shared",
bot_api_version="7.0",
)
return self._user_shared
@property
def forward_from(self) -> Optional[User]:
""":class:`telegram.User`: Optional. For forwarded messages, sender of the original
message.
.. deprecated:: 20.8
Bot API 7.0 deprecates :attr:`forward_from` in favor of :attr:`forward_origin`.
"""
warn_about_deprecated_attr_in_property(
deprecated_attr_name="forward_from",
new_attr_name="forward_origin",
bot_api_version="7.0",
)
return self._forward_from
@property
def forward_from_chat(self) -> Optional[Chat]:
""":class:`telegram.Chat`: Optional. For messages forwarded from channels or from anonymous
administrators, information about the original sender chat.
.. deprecated:: 20.8
Bot API 7.0 deprecates :attr:`forward_from_chat` in favor of :attr:`forward_origin`.
"""
warn_about_deprecated_attr_in_property(
deprecated_attr_name="forward_from_chat",
new_attr_name="forward_origin",
bot_api_version="7.0",
)
return self._forward_from_chat
@property
def forward_from_message_id(self) -> Optional[int]:
""":obj:`int`: Optional. For forwarded channel posts, identifier of the original message
in the channel.
.. deprecated:: 20.8
Bot API 7.0 deprecates :attr:`forward_from_message_id` in favor of
:attr:`forward_origin`.
"""
warn_about_deprecated_attr_in_property(
deprecated_attr_name="forward_from_message_id",
new_attr_name="forward_origin",
bot_api_version="7.0",
)
return self._forward_from_message_id
@property
def forward_signature(self) -> Optional[str]:
""":obj:`str`: Optional. For messages forwarded from channels, signature
of the post author if present.
.. deprecated:: 20.8
Bot API 7.0 deprecates :attr:`forward_signature` in favor of :attr:`forward_origin`.
"""
warn_about_deprecated_attr_in_property(
deprecated_attr_name="forward_signature",
new_attr_name="forward_origin",
bot_api_version="7.0",
)
return self._forward_signature
@property
def forward_sender_name(self) -> Optional[str]:
""":class:`telegram.User`: Optional. Sender's name for messages forwarded from users who
disallow adding a link to their account in forwarded messages.
.. deprecated:: 20.8
Bot API 7.0 deprecates :attr:`forward_sender_name` in favor of :attr:`forward_origin`.
"""
warn_about_deprecated_attr_in_property(
deprecated_attr_name="forward_sender_name",
new_attr_name="forward_origin",
bot_api_version="7.0",
)
return self._forward_sender_name
@property
def forward_date(self) -> Optional[datetime.datetime]:
""":obj:`datetime.datetime`: Optional. For forwarded messages, date the original message
was sent in Unix time. Converted to :class:`datetime.datetime`.
.. versionchanged:: 20.3
|datetime_localization|
.. deprecated:: 20.8
Bot API 7.0 deprecates :attr:`forward_date` in favor of :attr:`forward_origin`.
"""
warn_about_deprecated_attr_in_property(
deprecated_attr_name="forward_date",
new_attr_name="forward_origin",
bot_api_version="7.0",
)
return self._forward_date
@property
def chat_id(self) -> int:
""":obj:`int`: Shortcut for :attr:`telegram.Chat.id` for :attr:`chat`."""
@ -1373,9 +1099,6 @@ class Message(MaybeInaccessibleMessage):
data["sender_chat"] = Chat.de_json(data.get("sender_chat"), bot)
data["entities"] = MessageEntity.de_list(data.get("entities"), bot)
data["caption_entities"] = MessageEntity.de_list(data.get("caption_entities"), bot)
data["forward_from"] = User.de_json(data.get("forward_from"), bot)
data["forward_from_chat"] = Chat.de_json(data.get("forward_from_chat"), bot)
data["forward_date"] = from_timestamp(data.get("forward_date"), tzinfo=loc_tzinfo)
data["reply_to_message"] = Message.de_json(data.get("reply_to_message"), bot)
data["edit_date"] = from_timestamp(data.get("edit_date"), tzinfo=loc_tzinfo)
data["audio"] = Audio.de_json(data.get("audio"), bot)
@ -1434,7 +1157,6 @@ class Message(MaybeInaccessibleMessage):
data["write_access_allowed"] = WriteAccessAllowed.de_json(
data.get("write_access_allowed"), bot
)
data["user_shared"] = UserShared.de_json(data.get("user_shared"), bot)
data["users_shared"] = UsersShared.de_json(data.get("users_shared"), bot)
data["chat_shared"] = ChatShared.de_json(data.get("chat_shared"), bot)
@ -1464,7 +1186,24 @@ class Message(MaybeInaccessibleMessage):
data["quote"] = TextQuote.de_json(data.get("quote"), bot)
data["forward_origin"] = MessageOrigin.de_json(data.get("forward_origin"), bot)
return super().de_json(data=data, bot=bot) # type: ignore[return-value]
api_kwargs = {}
# This is a deprecated field that TG still returns for backwards compatibility
# Let's filter it out to speed up the de-json process
for key in (
"user_shared",
"forward_from",
"forward_from_chat",
"forward_from_message_id",
"forward_signature",
"forward_sender_name",
"forward_date",
):
if entry := data.get(key):
api_kwargs = {key: entry}
return super()._de_json( # type: ignore[return-value]
data=data, bot=bot, api_kwargs=api_kwargs
)
@property
def effective_attachment(
@ -1764,17 +1503,17 @@ class Message(MaybeInaccessibleMessage):
self,
text: str,
parse_mode: ODVInput[str] = DEFAULT_NONE,
disable_web_page_preview: ODVInput[bool] = DEFAULT_NONE,
disable_notification: ODVInput[bool] = DEFAULT_NONE,
reply_to_message_id: Optional[int] = None,
reply_markup: Optional[ReplyMarkup] = None,
allow_sending_without_reply: ODVInput[bool] = DEFAULT_NONE,
entities: Optional[Sequence["MessageEntity"]] = None,
protect_content: ODVInput[bool] = DEFAULT_NONE,
message_thread_id: Optional[int] = None,
link_preview_options: ODVInput["LinkPreviewOptions"] = DEFAULT_NONE,
reply_parameters: Optional["ReplyParameters"] = None,
*,
reply_to_message_id: Optional[int] = None,
allow_sending_without_reply: ODVInput[bool] = DEFAULT_NONE,
disable_web_page_preview: Optional[bool] = None,
quote: Optional[bool] = None,
do_quote: Optional[Union[bool, _ReplyKwargs]] = None,
read_timeout: ODVInput[float] = DEFAULT_NONE,
@ -1829,17 +1568,17 @@ class Message(MaybeInaccessibleMessage):
async def reply_markdown(
self,
text: str,
disable_web_page_preview: ODVInput[bool] = DEFAULT_NONE,
disable_notification: ODVInput[bool] = DEFAULT_NONE,
reply_to_message_id: Optional[int] = None,
reply_markup: Optional[ReplyMarkup] = None,
allow_sending_without_reply: ODVInput[bool] = DEFAULT_NONE,
entities: Optional[Sequence["MessageEntity"]] = None,
protect_content: ODVInput[bool] = DEFAULT_NONE,
message_thread_id: Optional[int] = None,
link_preview_options: ODVInput["LinkPreviewOptions"] = DEFAULT_NONE,
reply_parameters: Optional["ReplyParameters"] = None,
*,
reply_to_message_id: Optional[int] = None,
allow_sending_without_reply: ODVInput[bool] = DEFAULT_NONE,
disable_web_page_preview: Optional[bool] = None,
quote: Optional[bool] = None,
do_quote: Optional[Union[bool, _ReplyKwargs]] = None,
read_timeout: ODVInput[float] = DEFAULT_NONE,
@ -1904,17 +1643,17 @@ class Message(MaybeInaccessibleMessage):
async def reply_markdown_v2(
self,
text: str,
disable_web_page_preview: ODVInput[bool] = DEFAULT_NONE,
disable_notification: ODVInput[bool] = DEFAULT_NONE,
reply_to_message_id: Optional[int] = None,
reply_markup: Optional[ReplyMarkup] = None,
allow_sending_without_reply: ODVInput[bool] = DEFAULT_NONE,
entities: Optional[Sequence["MessageEntity"]] = None,
protect_content: ODVInput[bool] = DEFAULT_NONE,
message_thread_id: Optional[int] = None,
link_preview_options: ODVInput["LinkPreviewOptions"] = DEFAULT_NONE,
reply_parameters: Optional["ReplyParameters"] = None,
*,
reply_to_message_id: Optional[int] = None,
allow_sending_without_reply: ODVInput[bool] = DEFAULT_NONE,
disable_web_page_preview: Optional[bool] = None,
quote: Optional[bool] = None,
do_quote: Optional[Union[bool, _ReplyKwargs]] = None,
read_timeout: ODVInput[float] = DEFAULT_NONE,
@ -1975,17 +1714,17 @@ class Message(MaybeInaccessibleMessage):
async def reply_html(
self,
text: str,
disable_web_page_preview: ODVInput[bool] = DEFAULT_NONE,
disable_notification: ODVInput[bool] = DEFAULT_NONE,
reply_to_message_id: Optional[int] = None,
reply_markup: Optional[ReplyMarkup] = None,
allow_sending_without_reply: ODVInput[bool] = DEFAULT_NONE,
entities: Optional[Sequence["MessageEntity"]] = None,
protect_content: ODVInput[bool] = DEFAULT_NONE,
message_thread_id: Optional[int] = None,
link_preview_options: ODVInput["LinkPreviewOptions"] = DEFAULT_NONE,
reply_parameters: Optional["ReplyParameters"] = None,
*,
reply_to_message_id: Optional[int] = None,
allow_sending_without_reply: ODVInput[bool] = DEFAULT_NONE,
disable_web_page_preview: Optional[bool] = None,
quote: Optional[bool] = None,
do_quote: Optional[Union[bool, _ReplyKwargs]] = None,
read_timeout: ODVInput[float] = DEFAULT_NONE,
@ -2049,12 +1788,12 @@ class Message(MaybeInaccessibleMessage):
Union["InputMediaAudio", "InputMediaDocument", "InputMediaPhoto", "InputMediaVideo"]
],
disable_notification: ODVInput[bool] = DEFAULT_NONE,
reply_to_message_id: Optional[int] = None,
allow_sending_without_reply: ODVInput[bool] = DEFAULT_NONE,
protect_content: ODVInput[bool] = DEFAULT_NONE,
message_thread_id: Optional[int] = None,
reply_parameters: Optional["ReplyParameters"] = None,
*,
reply_to_message_id: Optional[int] = None,
allow_sending_without_reply: ODVInput[bool] = DEFAULT_NONE,
quote: Optional[bool] = None,
do_quote: Optional[Union[bool, _ReplyKwargs]] = None,
read_timeout: ODVInput[float] = DEFAULT_NONE,
@ -2114,16 +1853,16 @@ class Message(MaybeInaccessibleMessage):
photo: Union[FileInput, "PhotoSize"],
caption: Optional[str] = None,
disable_notification: ODVInput[bool] = DEFAULT_NONE,
reply_to_message_id: Optional[int] = None,
reply_markup: Optional[ReplyMarkup] = None,
parse_mode: ODVInput[str] = DEFAULT_NONE,
allow_sending_without_reply: ODVInput[bool] = DEFAULT_NONE,
caption_entities: Optional[Sequence["MessageEntity"]] = None,
protect_content: ODVInput[bool] = DEFAULT_NONE,
message_thread_id: Optional[int] = None,
has_spoiler: Optional[bool] = None,
reply_parameters: Optional["ReplyParameters"] = None,
*,
reply_to_message_id: Optional[int] = None,
allow_sending_without_reply: ODVInput[bool] = DEFAULT_NONE,
filename: Optional[str] = None,
quote: Optional[bool] = None,
do_quote: Optional[Union[bool, _ReplyKwargs]] = None,
@ -2185,16 +1924,16 @@ class Message(MaybeInaccessibleMessage):
title: Optional[str] = None,
caption: Optional[str] = None,
disable_notification: ODVInput[bool] = DEFAULT_NONE,
reply_to_message_id: Optional[int] = None,
reply_markup: Optional[ReplyMarkup] = None,
parse_mode: ODVInput[str] = DEFAULT_NONE,
allow_sending_without_reply: ODVInput[bool] = DEFAULT_NONE,
caption_entities: Optional[Sequence["MessageEntity"]] = None,
protect_content: ODVInput[bool] = DEFAULT_NONE,
message_thread_id: Optional[int] = None,
thumbnail: Optional[FileInput] = None,
reply_parameters: Optional["ReplyParameters"] = None,
*,
reply_to_message_id: Optional[int] = None,
allow_sending_without_reply: ODVInput[bool] = DEFAULT_NONE,
filename: Optional[str] = None,
quote: Optional[bool] = None,
do_quote: Optional[Union[bool, _ReplyKwargs]] = None,
@ -2256,17 +1995,17 @@ class Message(MaybeInaccessibleMessage):
document: Union[FileInput, "Document"],
caption: Optional[str] = None,
disable_notification: ODVInput[bool] = DEFAULT_NONE,
reply_to_message_id: Optional[int] = None,
reply_markup: Optional[ReplyMarkup] = None,
parse_mode: ODVInput[str] = DEFAULT_NONE,
disable_content_type_detection: Optional[bool] = None,
allow_sending_without_reply: ODVInput[bool] = DEFAULT_NONE,
caption_entities: Optional[Sequence["MessageEntity"]] = None,
protect_content: ODVInput[bool] = DEFAULT_NONE,
message_thread_id: Optional[int] = None,
thumbnail: Optional[FileInput] = None,
reply_parameters: Optional["ReplyParameters"] = None,
*,
reply_to_message_id: Optional[int] = None,
allow_sending_without_reply: ODVInput[bool] = DEFAULT_NONE,
filename: Optional[str] = None,
quote: Optional[bool] = None,
do_quote: Optional[Union[bool, _ReplyKwargs]] = None,
@ -2330,9 +2069,7 @@ class Message(MaybeInaccessibleMessage):
caption: Optional[str] = None,
parse_mode: ODVInput[str] = DEFAULT_NONE,
disable_notification: ODVInput[bool] = DEFAULT_NONE,
reply_to_message_id: Optional[int] = None,
reply_markup: Optional[ReplyMarkup] = None,
allow_sending_without_reply: ODVInput[bool] = DEFAULT_NONE,
caption_entities: Optional[Sequence["MessageEntity"]] = None,
protect_content: ODVInput[bool] = DEFAULT_NONE,
message_thread_id: Optional[int] = None,
@ -2340,6 +2077,8 @@ class Message(MaybeInaccessibleMessage):
thumbnail: Optional[FileInput] = None,
reply_parameters: Optional["ReplyParameters"] = None,
*,
reply_to_message_id: Optional[int] = None,
allow_sending_without_reply: ODVInput[bool] = DEFAULT_NONE,
filename: Optional[str] = None,
quote: Optional[bool] = None,
do_quote: Optional[Union[bool, _ReplyKwargs]] = None,
@ -2401,14 +2140,14 @@ class Message(MaybeInaccessibleMessage):
self,
sticker: Union[FileInput, "Sticker"],
disable_notification: ODVInput[bool] = DEFAULT_NONE,
reply_to_message_id: Optional[int] = None,
reply_markup: Optional[ReplyMarkup] = None,
allow_sending_without_reply: ODVInput[bool] = DEFAULT_NONE,
protect_content: ODVInput[bool] = DEFAULT_NONE,
message_thread_id: Optional[int] = None,
emoji: Optional[str] = None,
reply_parameters: Optional["ReplyParameters"] = None,
*,
reply_to_message_id: Optional[int] = None,
allow_sending_without_reply: ODVInput[bool] = DEFAULT_NONE,
quote: Optional[bool] = None,
do_quote: Optional[Union[bool, _ReplyKwargs]] = None,
read_timeout: ODVInput[float] = DEFAULT_NONE,
@ -2463,13 +2202,11 @@ class Message(MaybeInaccessibleMessage):
duration: Optional[int] = None,
caption: Optional[str] = None,
disable_notification: ODVInput[bool] = DEFAULT_NONE,
reply_to_message_id: Optional[int] = None,
reply_markup: Optional[ReplyMarkup] = None,
width: Optional[int] = None,
height: Optional[int] = None,
parse_mode: ODVInput[str] = DEFAULT_NONE,
supports_streaming: Optional[bool] = None,
allow_sending_without_reply: ODVInput[bool] = DEFAULT_NONE,
caption_entities: Optional[Sequence["MessageEntity"]] = None,
protect_content: ODVInput[bool] = DEFAULT_NONE,
message_thread_id: Optional[int] = None,
@ -2477,6 +2214,8 @@ class Message(MaybeInaccessibleMessage):
thumbnail: Optional[FileInput] = None,
reply_parameters: Optional["ReplyParameters"] = None,
*,
reply_to_message_id: Optional[int] = None,
allow_sending_without_reply: ODVInput[bool] = DEFAULT_NONE,
filename: Optional[str] = None,
quote: Optional[bool] = None,
do_quote: Optional[Union[bool, _ReplyKwargs]] = None,
@ -2541,14 +2280,14 @@ class Message(MaybeInaccessibleMessage):
duration: Optional[int] = None,
length: Optional[int] = None,
disable_notification: ODVInput[bool] = DEFAULT_NONE,
reply_to_message_id: Optional[int] = None,
reply_markup: Optional[ReplyMarkup] = None,
allow_sending_without_reply: ODVInput[bool] = DEFAULT_NONE,
protect_content: ODVInput[bool] = DEFAULT_NONE,
message_thread_id: Optional[int] = None,
thumbnail: Optional[FileInput] = None,
reply_parameters: Optional["ReplyParameters"] = None,
*,
reply_to_message_id: Optional[int] = None,
allow_sending_without_reply: ODVInput[bool] = DEFAULT_NONE,
filename: Optional[str] = None,
quote: Optional[bool] = None,
do_quote: Optional[Union[bool, _ReplyKwargs]] = None,
@ -2607,15 +2346,15 @@ class Message(MaybeInaccessibleMessage):
duration: Optional[int] = None,
caption: Optional[str] = None,
disable_notification: ODVInput[bool] = DEFAULT_NONE,
reply_to_message_id: Optional[int] = None,
reply_markup: Optional[ReplyMarkup] = None,
parse_mode: ODVInput[str] = DEFAULT_NONE,
allow_sending_without_reply: ODVInput[bool] = DEFAULT_NONE,
caption_entities: Optional[Sequence["MessageEntity"]] = None,
protect_content: ODVInput[bool] = DEFAULT_NONE,
message_thread_id: Optional[int] = None,
reply_parameters: Optional["ReplyParameters"] = None,
*,
reply_to_message_id: Optional[int] = None,
allow_sending_without_reply: ODVInput[bool] = DEFAULT_NONE,
filename: Optional[str] = None,
quote: Optional[bool] = None,
do_quote: Optional[Union[bool, _ReplyKwargs]] = None,
@ -2674,17 +2413,17 @@ class Message(MaybeInaccessibleMessage):
latitude: Optional[float] = None,
longitude: Optional[float] = None,
disable_notification: ODVInput[bool] = DEFAULT_NONE,
reply_to_message_id: Optional[int] = None,
reply_markup: Optional[ReplyMarkup] = None,
live_period: Optional[int] = None,
horizontal_accuracy: Optional[float] = None,
heading: Optional[int] = None,
proximity_alert_radius: Optional[int] = None,
allow_sending_without_reply: ODVInput[bool] = DEFAULT_NONE,
protect_content: ODVInput[bool] = DEFAULT_NONE,
message_thread_id: Optional[int] = None,
reply_parameters: Optional["ReplyParameters"] = None,
*,
reply_to_message_id: Optional[int] = None,
allow_sending_without_reply: ODVInput[bool] = DEFAULT_NONE,
location: Optional[Location] = None,
quote: Optional[bool] = None,
do_quote: Optional[Union[bool, _ReplyKwargs]] = None,
@ -2747,16 +2486,16 @@ class Message(MaybeInaccessibleMessage):
address: Optional[str] = None,
foursquare_id: Optional[str] = None,
disable_notification: ODVInput[bool] = DEFAULT_NONE,
reply_to_message_id: Optional[int] = None,
reply_markup: Optional[ReplyMarkup] = None,
foursquare_type: Optional[str] = None,
google_place_id: Optional[str] = None,
google_place_type: Optional[str] = None,
allow_sending_without_reply: ODVInput[bool] = DEFAULT_NONE,
protect_content: ODVInput[bool] = DEFAULT_NONE,
message_thread_id: Optional[int] = None,
reply_parameters: Optional["ReplyParameters"] = None,
*,
reply_to_message_id: Optional[int] = None,
allow_sending_without_reply: ODVInput[bool] = DEFAULT_NONE,
venue: Optional[Venue] = None,
quote: Optional[bool] = None,
do_quote: Optional[Union[bool, _ReplyKwargs]] = None,
@ -2819,14 +2558,14 @@ class Message(MaybeInaccessibleMessage):
first_name: Optional[str] = None,
last_name: Optional[str] = None,
disable_notification: ODVInput[bool] = DEFAULT_NONE,
reply_to_message_id: Optional[int] = None,
reply_markup: Optional[ReplyMarkup] = None,
vcard: Optional[str] = None,
allow_sending_without_reply: ODVInput[bool] = DEFAULT_NONE,
protect_content: ODVInput[bool] = DEFAULT_NONE,
message_thread_id: Optional[int] = None,
reply_parameters: Optional["ReplyParameters"] = None,
*,
reply_to_message_id: Optional[int] = None,
allow_sending_without_reply: ODVInput[bool] = DEFAULT_NONE,
contact: Optional[Contact] = None,
quote: Optional[bool] = None,
do_quote: Optional[Union[bool, _ReplyKwargs]] = None,
@ -2889,18 +2628,18 @@ class Message(MaybeInaccessibleMessage):
correct_option_id: Optional[CorrectOptionID] = None,
is_closed: Optional[bool] = None,
disable_notification: ODVInput[bool] = DEFAULT_NONE,
reply_to_message_id: Optional[int] = None,
reply_markup: Optional[ReplyMarkup] = None,
explanation: Optional[str] = None,
explanation_parse_mode: ODVInput[str] = DEFAULT_NONE,
open_period: Optional[int] = None,
close_date: Optional[Union[int, datetime.datetime]] = None,
allow_sending_without_reply: ODVInput[bool] = DEFAULT_NONE,
explanation_entities: Optional[Sequence["MessageEntity"]] = None,
protect_content: ODVInput[bool] = DEFAULT_NONE,
message_thread_id: Optional[int] = None,
reply_parameters: Optional["ReplyParameters"] = None,
*,
reply_to_message_id: Optional[int] = None,
allow_sending_without_reply: ODVInput[bool] = DEFAULT_NONE,
quote: Optional[bool] = None,
do_quote: Optional[Union[bool, _ReplyKwargs]] = None,
read_timeout: ODVInput[float] = DEFAULT_NONE,
@ -2962,14 +2701,14 @@ class Message(MaybeInaccessibleMessage):
async def reply_dice(
self,
disable_notification: ODVInput[bool] = DEFAULT_NONE,
reply_to_message_id: Optional[int] = None,
reply_markup: Optional[ReplyMarkup] = None,
emoji: Optional[str] = None,
allow_sending_without_reply: ODVInput[bool] = DEFAULT_NONE,
protect_content: ODVInput[bool] = DEFAULT_NONE,
message_thread_id: Optional[int] = None,
reply_parameters: Optional["ReplyParameters"] = None,
*,
reply_to_message_id: Optional[int] = None,
allow_sending_without_reply: ODVInput[bool] = DEFAULT_NONE,
quote: Optional[bool] = None,
do_quote: Optional[Union[bool, _ReplyKwargs]] = None,
read_timeout: ODVInput[float] = DEFAULT_NONE,
@ -3055,13 +2794,13 @@ class Message(MaybeInaccessibleMessage):
self,
game_short_name: str,
disable_notification: ODVInput[bool] = DEFAULT_NONE,
reply_to_message_id: Optional[int] = None,
reply_markup: Optional["InlineKeyboardMarkup"] = None,
allow_sending_without_reply: ODVInput[bool] = DEFAULT_NONE,
protect_content: ODVInput[bool] = DEFAULT_NONE,
message_thread_id: Optional[int] = None,
reply_parameters: Optional["ReplyParameters"] = None,
*,
reply_to_message_id: Optional[int] = None,
allow_sending_without_reply: ODVInput[bool] = DEFAULT_NONE,
quote: Optional[bool] = None,
do_quote: Optional[Union[bool, _ReplyKwargs]] = None,
read_timeout: ODVInput[float] = DEFAULT_NONE,
@ -3130,18 +2869,18 @@ class Message(MaybeInaccessibleMessage):
need_shipping_address: Optional[bool] = None,
is_flexible: Optional[bool] = None,
disable_notification: ODVInput[bool] = DEFAULT_NONE,
reply_to_message_id: Optional[int] = None,
reply_markup: Optional["InlineKeyboardMarkup"] = None,
provider_data: Optional[Union[str, object]] = None,
send_phone_number_to_provider: Optional[bool] = None,
send_email_to_provider: Optional[bool] = None,
allow_sending_without_reply: ODVInput[bool] = DEFAULT_NONE,
max_tip_amount: Optional[int] = None,
suggested_tip_amounts: Optional[Sequence[int]] = None,
protect_content: ODVInput[bool] = DEFAULT_NONE,
message_thread_id: Optional[int] = None,
reply_parameters: Optional["ReplyParameters"] = None,
*,
reply_to_message_id: Optional[int] = None,
allow_sending_without_reply: ODVInput[bool] = DEFAULT_NONE,
quote: Optional[bool] = None,
do_quote: Optional[Union[bool, _ReplyKwargs]] = None,
read_timeout: ODVInput[float] = DEFAULT_NONE,
@ -3278,13 +3017,13 @@ class Message(MaybeInaccessibleMessage):
parse_mode: ODVInput[str] = DEFAULT_NONE,
caption_entities: Optional[Sequence["MessageEntity"]] = None,
disable_notification: ODVInput[bool] = DEFAULT_NONE,
reply_to_message_id: Optional[int] = None,
allow_sending_without_reply: ODVInput[bool] = DEFAULT_NONE,
reply_markup: Optional[ReplyMarkup] = None,
protect_content: ODVInput[bool] = DEFAULT_NONE,
message_thread_id: Optional[int] = None,
reply_parameters: Optional["ReplyParameters"] = None,
*,
reply_to_message_id: Optional[int] = None,
allow_sending_without_reply: ODVInput[bool] = DEFAULT_NONE,
read_timeout: ODVInput[float] = DEFAULT_NONE,
write_timeout: ODVInput[float] = DEFAULT_NONE,
connect_timeout: ODVInput[float] = DEFAULT_NONE,
@ -3336,13 +3075,13 @@ class Message(MaybeInaccessibleMessage):
parse_mode: ODVInput[str] = DEFAULT_NONE,
caption_entities: Optional[Sequence["MessageEntity"]] = None,
disable_notification: ODVInput[bool] = DEFAULT_NONE,
reply_to_message_id: Optional[int] = None,
allow_sending_without_reply: ODVInput[bool] = DEFAULT_NONE,
reply_markup: Optional[ReplyMarkup] = None,
protect_content: ODVInput[bool] = DEFAULT_NONE,
message_thread_id: Optional[int] = None,
reply_parameters: Optional["ReplyParameters"] = None,
*,
reply_to_message_id: Optional[int] = None,
allow_sending_without_reply: ODVInput[bool] = DEFAULT_NONE,
quote: Optional[bool] = None,
do_quote: Optional[Union[bool, _ReplyKwargs]] = None,
read_timeout: ODVInput[float] = DEFAULT_NONE,
@ -3404,11 +3143,11 @@ class Message(MaybeInaccessibleMessage):
self,
text: str,
parse_mode: ODVInput[str] = DEFAULT_NONE,
disable_web_page_preview: ODVInput[bool] = DEFAULT_NONE,
reply_markup: Optional["InlineKeyboardMarkup"] = None,
entities: Optional[Sequence["MessageEntity"]] = None,
link_preview_options: ODVInput["LinkPreviewOptions"] = DEFAULT_NONE,
*,
disable_web_page_preview: Optional[bool] = None,
read_timeout: ODVInput[float] = DEFAULT_NONE,
write_timeout: ODVInput[float] = DEFAULT_NONE,
connect_timeout: ODVInput[float] = DEFAULT_NONE,

View file

@ -21,12 +21,6 @@ from typing import Optional, Sequence, Tuple
from telegram._telegramobject import TelegramObject
from telegram._utils.types import JSONDict
from telegram._utils.warnings import warn
from telegram._utils.warnings_transition import (
build_deprecation_warning_message,
warn_about_deprecated_attr_in_property,
)
from telegram.warnings import PTBDeprecationWarning
class UsersShared(TelegramObject):
@ -38,7 +32,7 @@ class UsersShared(TelegramObject):
considered equal, if their :attr:`request_id` and :attr:`user_ids` are equal.
.. versionadded:: 20.8
Bot API 7.0 replaces :class:`UserShared` with this class. The only difference is that now
Bot API 7.0 replaces ``UserShared`` with this class. The only difference is that now
the :attr:`user_ids` is a sequence instead of a single integer.
Args:
@ -78,55 +72,6 @@ class UsersShared(TelegramObject):
self._freeze()
class UserShared(UsersShared):
"""Alias for :class:`UsersShared`, kept for backward compatibility.
.. versionadded:: 20.1
.. deprecated:: 20.8
Use :class:`UsersShared` instead.
"""
__slots__ = ()
def __init__(
self,
request_id: int,
user_id: int,
*,
api_kwargs: Optional[JSONDict] = None,
):
super().__init__(request_id, (user_id,), api_kwargs=api_kwargs)
warn(
build_deprecation_warning_message(
deprecated_name="UserShared",
new_name="UsersShared",
object_type="class",
bot_api_version="7.0",
),
PTBDeprecationWarning,
stacklevel=2,
)
self._freeze()
@property
def user_id(self) -> int:
"""Alias for the first entry of :attr:`UsersShared.user_ids`.
.. deprecated:: 20.8
Bot API 7.0 deprecates this attribute in favor of :attr:`UsersShared.user_ids`.
"""
warn_about_deprecated_attr_in_property(
deprecated_attr_name="user_id",
new_attr_name="user_ids",
bot_api_version="7.0",
)
return self.user_ids[0]
class ChatShared(TelegramObject):
"""
This object contains information about the chat whose identifier was shared with the bot

View file

@ -386,17 +386,17 @@ class User(TelegramObject):
self,
text: str,
parse_mode: ODVInput[str] = DEFAULT_NONE,
disable_web_page_preview: ODVInput[bool] = DEFAULT_NONE,
disable_notification: ODVInput[bool] = DEFAULT_NONE,
reply_to_message_id: Optional[int] = None,
reply_markup: Optional[ReplyMarkup] = None,
allow_sending_without_reply: ODVInput[bool] = DEFAULT_NONE,
entities: Optional[Sequence["MessageEntity"]] = None,
protect_content: ODVInput[bool] = DEFAULT_NONE,
message_thread_id: Optional[int] = None,
link_preview_options: ODVInput["LinkPreviewOptions"] = DEFAULT_NONE,
reply_parameters: Optional["ReplyParameters"] = None,
*,
reply_to_message_id: Optional[int] = None,
disable_web_page_preview: Optional[bool] = None,
allow_sending_without_reply: ODVInput[bool] = DEFAULT_NONE,
read_timeout: ODVInput[float] = DEFAULT_NONE,
write_timeout: ODVInput[float] = DEFAULT_NONE,
connect_timeout: ODVInput[float] = DEFAULT_NONE,
@ -506,16 +506,16 @@ class User(TelegramObject):
photo: Union[FileInput, "PhotoSize"],
caption: Optional[str] = None,
disable_notification: ODVInput[bool] = DEFAULT_NONE,
reply_to_message_id: Optional[int] = None,
reply_markup: Optional[ReplyMarkup] = None,
parse_mode: ODVInput[str] = DEFAULT_NONE,
allow_sending_without_reply: ODVInput[bool] = DEFAULT_NONE,
caption_entities: Optional[Sequence["MessageEntity"]] = None,
protect_content: ODVInput[bool] = DEFAULT_NONE,
message_thread_id: Optional[int] = None,
has_spoiler: Optional[bool] = None,
reply_parameters: Optional["ReplyParameters"] = None,
*,
reply_to_message_id: Optional[int] = None,
allow_sending_without_reply: ODVInput[bool] = DEFAULT_NONE,
filename: Optional[str] = None,
read_timeout: ODVInput[float] = DEFAULT_NONE,
write_timeout: ODVInput[float] = DEFAULT_NONE,
@ -564,12 +564,12 @@ class User(TelegramObject):
Union["InputMediaAudio", "InputMediaDocument", "InputMediaPhoto", "InputMediaVideo"]
],
disable_notification: ODVInput[bool] = DEFAULT_NONE,
reply_to_message_id: Optional[int] = None,
allow_sending_without_reply: ODVInput[bool] = DEFAULT_NONE,
protect_content: ODVInput[bool] = DEFAULT_NONE,
message_thread_id: Optional[int] = None,
reply_parameters: Optional["ReplyParameters"] = None,
*,
reply_to_message_id: Optional[int] = None,
allow_sending_without_reply: ODVInput[bool] = DEFAULT_NONE,
read_timeout: ODVInput[float] = DEFAULT_NONE,
write_timeout: ODVInput[float] = DEFAULT_NONE,
connect_timeout: ODVInput[float] = DEFAULT_NONE,
@ -620,16 +620,16 @@ class User(TelegramObject):
title: Optional[str] = None,
caption: Optional[str] = None,
disable_notification: ODVInput[bool] = DEFAULT_NONE,
reply_to_message_id: Optional[int] = None,
reply_markup: Optional[ReplyMarkup] = None,
parse_mode: ODVInput[str] = DEFAULT_NONE,
allow_sending_without_reply: ODVInput[bool] = DEFAULT_NONE,
caption_entities: Optional[Sequence["MessageEntity"]] = None,
protect_content: ODVInput[bool] = DEFAULT_NONE,
message_thread_id: Optional[int] = None,
thumbnail: Optional[FileInput] = None,
reply_parameters: Optional["ReplyParameters"] = None,
*,
reply_to_message_id: Optional[int] = None,
allow_sending_without_reply: ODVInput[bool] = DEFAULT_NONE,
filename: Optional[str] = None,
read_timeout: ODVInput[float] = DEFAULT_NONE,
write_timeout: ODVInput[float] = DEFAULT_NONE,
@ -719,14 +719,14 @@ class User(TelegramObject):
first_name: Optional[str] = None,
last_name: Optional[str] = None,
disable_notification: ODVInput[bool] = DEFAULT_NONE,
reply_to_message_id: Optional[int] = None,
reply_markup: Optional[ReplyMarkup] = None,
vcard: Optional[str] = None,
allow_sending_without_reply: ODVInput[bool] = DEFAULT_NONE,
protect_content: ODVInput[bool] = DEFAULT_NONE,
message_thread_id: Optional[int] = None,
reply_parameters: Optional["ReplyParameters"] = None,
*,
reply_to_message_id: Optional[int] = None,
allow_sending_without_reply: ODVInput[bool] = DEFAULT_NONE,
contact: Optional["Contact"] = None,
read_timeout: ODVInput[float] = DEFAULT_NONE,
write_timeout: ODVInput[float] = DEFAULT_NONE,
@ -771,14 +771,14 @@ class User(TelegramObject):
async def send_dice(
self,
disable_notification: ODVInput[bool] = DEFAULT_NONE,
reply_to_message_id: Optional[int] = None,
reply_markup: Optional[ReplyMarkup] = None,
emoji: Optional[str] = None,
allow_sending_without_reply: ODVInput[bool] = DEFAULT_NONE,
protect_content: ODVInput[bool] = DEFAULT_NONE,
message_thread_id: Optional[int] = None,
reply_parameters: Optional["ReplyParameters"] = None,
*,
reply_to_message_id: Optional[int] = None,
allow_sending_without_reply: ODVInput[bool] = DEFAULT_NONE,
read_timeout: ODVInput[float] = DEFAULT_NONE,
write_timeout: ODVInput[float] = DEFAULT_NONE,
connect_timeout: ODVInput[float] = DEFAULT_NONE,
@ -820,17 +820,17 @@ class User(TelegramObject):
document: Union[FileInput, "Document"],
caption: Optional[str] = None,
disable_notification: ODVInput[bool] = DEFAULT_NONE,
reply_to_message_id: Optional[int] = None,
reply_markup: Optional[ReplyMarkup] = None,
parse_mode: ODVInput[str] = DEFAULT_NONE,
disable_content_type_detection: Optional[bool] = None,
allow_sending_without_reply: ODVInput[bool] = DEFAULT_NONE,
caption_entities: Optional[Sequence["MessageEntity"]] = None,
protect_content: ODVInput[bool] = DEFAULT_NONE,
message_thread_id: Optional[int] = None,
thumbnail: Optional[FileInput] = None,
reply_parameters: Optional["ReplyParameters"] = None,
*,
reply_to_message_id: Optional[int] = None,
allow_sending_without_reply: ODVInput[bool] = DEFAULT_NONE,
filename: Optional[str] = None,
read_timeout: ODVInput[float] = DEFAULT_NONE,
write_timeout: ODVInput[float] = DEFAULT_NONE,
@ -878,13 +878,13 @@ class User(TelegramObject):
self,
game_short_name: str,
disable_notification: ODVInput[bool] = DEFAULT_NONE,
reply_to_message_id: Optional[int] = None,
reply_markup: Optional["InlineKeyboardMarkup"] = None,
allow_sending_without_reply: ODVInput[bool] = DEFAULT_NONE,
protect_content: ODVInput[bool] = DEFAULT_NONE,
message_thread_id: Optional[int] = None,
reply_parameters: Optional["ReplyParameters"] = None,
*,
reply_to_message_id: Optional[int] = None,
allow_sending_without_reply: ODVInput[bool] = DEFAULT_NONE,
read_timeout: ODVInput[float] = DEFAULT_NONE,
write_timeout: ODVInput[float] = DEFAULT_NONE,
connect_timeout: ODVInput[float] = DEFAULT_NONE,
@ -940,18 +940,18 @@ class User(TelegramObject):
need_shipping_address: Optional[bool] = None,
is_flexible: Optional[bool] = None,
disable_notification: ODVInput[bool] = DEFAULT_NONE,
reply_to_message_id: Optional[int] = None,
reply_markup: Optional["InlineKeyboardMarkup"] = None,
provider_data: Optional[Union[str, object]] = None,
send_phone_number_to_provider: Optional[bool] = None,
send_email_to_provider: Optional[bool] = None,
allow_sending_without_reply: ODVInput[bool] = DEFAULT_NONE,
max_tip_amount: Optional[int] = None,
suggested_tip_amounts: Optional[Sequence[int]] = None,
protect_content: ODVInput[bool] = DEFAULT_NONE,
message_thread_id: Optional[int] = None,
reply_parameters: Optional["ReplyParameters"] = None,
*,
reply_to_message_id: Optional[int] = None,
allow_sending_without_reply: ODVInput[bool] = DEFAULT_NONE,
read_timeout: ODVInput[float] = DEFAULT_NONE,
write_timeout: ODVInput[float] = DEFAULT_NONE,
connect_timeout: ODVInput[float] = DEFAULT_NONE,
@ -1023,17 +1023,17 @@ class User(TelegramObject):
latitude: Optional[float] = None,
longitude: Optional[float] = None,
disable_notification: ODVInput[bool] = DEFAULT_NONE,
reply_to_message_id: Optional[int] = None,
reply_markup: Optional[ReplyMarkup] = None,
live_period: Optional[int] = None,
horizontal_accuracy: Optional[float] = None,
heading: Optional[int] = None,
proximity_alert_radius: Optional[int] = None,
allow_sending_without_reply: ODVInput[bool] = DEFAULT_NONE,
protect_content: ODVInput[bool] = DEFAULT_NONE,
message_thread_id: Optional[int] = None,
reply_parameters: Optional["ReplyParameters"] = None,
*,
reply_to_message_id: Optional[int] = None,
allow_sending_without_reply: ODVInput[bool] = DEFAULT_NONE,
location: Optional["Location"] = None,
read_timeout: ODVInput[float] = DEFAULT_NONE,
write_timeout: ODVInput[float] = DEFAULT_NONE,
@ -1086,9 +1086,7 @@ class User(TelegramObject):
caption: Optional[str] = None,
parse_mode: ODVInput[str] = DEFAULT_NONE,
disable_notification: ODVInput[bool] = DEFAULT_NONE,
reply_to_message_id: Optional[int] = None,
reply_markup: Optional[ReplyMarkup] = None,
allow_sending_without_reply: ODVInput[bool] = DEFAULT_NONE,
caption_entities: Optional[Sequence["MessageEntity"]] = None,
protect_content: ODVInput[bool] = DEFAULT_NONE,
message_thread_id: Optional[int] = None,
@ -1096,6 +1094,8 @@ class User(TelegramObject):
thumbnail: Optional[FileInput] = None,
reply_parameters: Optional["ReplyParameters"] = None,
*,
reply_to_message_id: Optional[int] = None,
allow_sending_without_reply: ODVInput[bool] = DEFAULT_NONE,
filename: Optional[str] = None,
read_timeout: ODVInput[float] = DEFAULT_NONE,
write_timeout: ODVInput[float] = DEFAULT_NONE,
@ -1146,14 +1146,14 @@ class User(TelegramObject):
self,
sticker: Union[FileInput, "Sticker"],
disable_notification: ODVInput[bool] = DEFAULT_NONE,
reply_to_message_id: Optional[int] = None,
reply_markup: Optional[ReplyMarkup] = None,
allow_sending_without_reply: ODVInput[bool] = DEFAULT_NONE,
protect_content: ODVInput[bool] = DEFAULT_NONE,
message_thread_id: Optional[int] = None,
emoji: Optional[str] = None,
reply_parameters: Optional["ReplyParameters"] = None,
*,
reply_to_message_id: Optional[int] = None,
allow_sending_without_reply: ODVInput[bool] = DEFAULT_NONE,
read_timeout: ODVInput[float] = DEFAULT_NONE,
write_timeout: ODVInput[float] = DEFAULT_NONE,
connect_timeout: ODVInput[float] = DEFAULT_NONE,
@ -1197,13 +1197,11 @@ class User(TelegramObject):
duration: Optional[int] = None,
caption: Optional[str] = None,
disable_notification: ODVInput[bool] = DEFAULT_NONE,
reply_to_message_id: Optional[int] = None,
reply_markup: Optional[ReplyMarkup] = None,
width: Optional[int] = None,
height: Optional[int] = None,
parse_mode: ODVInput[str] = DEFAULT_NONE,
supports_streaming: Optional[bool] = None,
allow_sending_without_reply: ODVInput[bool] = DEFAULT_NONE,
caption_entities: Optional[Sequence["MessageEntity"]] = None,
protect_content: ODVInput[bool] = DEFAULT_NONE,
message_thread_id: Optional[int] = None,
@ -1211,6 +1209,8 @@ class User(TelegramObject):
thumbnail: Optional[FileInput] = None,
reply_parameters: Optional["ReplyParameters"] = None,
*,
reply_to_message_id: Optional[int] = None,
allow_sending_without_reply: ODVInput[bool] = DEFAULT_NONE,
filename: Optional[str] = None,
read_timeout: ODVInput[float] = DEFAULT_NONE,
write_timeout: ODVInput[float] = DEFAULT_NONE,
@ -1266,16 +1266,16 @@ class User(TelegramObject):
address: Optional[str] = None,
foursquare_id: Optional[str] = None,
disable_notification: ODVInput[bool] = DEFAULT_NONE,
reply_to_message_id: Optional[int] = None,
reply_markup: Optional[ReplyMarkup] = None,
foursquare_type: Optional[str] = None,
google_place_id: Optional[str] = None,
google_place_type: Optional[str] = None,
allow_sending_without_reply: ODVInput[bool] = DEFAULT_NONE,
protect_content: ODVInput[bool] = DEFAULT_NONE,
message_thread_id: Optional[int] = None,
reply_parameters: Optional["ReplyParameters"] = None,
*,
reply_to_message_id: Optional[int] = None,
allow_sending_without_reply: ODVInput[bool] = DEFAULT_NONE,
venue: Optional["Venue"] = None,
read_timeout: ODVInput[float] = DEFAULT_NONE,
write_timeout: ODVInput[float] = DEFAULT_NONE,
@ -1327,14 +1327,14 @@ class User(TelegramObject):
duration: Optional[int] = None,
length: Optional[int] = None,
disable_notification: ODVInput[bool] = DEFAULT_NONE,
reply_to_message_id: Optional[int] = None,
reply_markup: Optional[ReplyMarkup] = None,
allow_sending_without_reply: ODVInput[bool] = DEFAULT_NONE,
protect_content: ODVInput[bool] = DEFAULT_NONE,
message_thread_id: Optional[int] = None,
thumbnail: Optional[FileInput] = None,
reply_parameters: Optional["ReplyParameters"] = None,
*,
reply_to_message_id: Optional[int] = None,
allow_sending_without_reply: ODVInput[bool] = DEFAULT_NONE,
filename: Optional[str] = None,
read_timeout: ODVInput[float] = DEFAULT_NONE,
write_timeout: ODVInput[float] = DEFAULT_NONE,
@ -1382,15 +1382,15 @@ class User(TelegramObject):
duration: Optional[int] = None,
caption: Optional[str] = None,
disable_notification: ODVInput[bool] = DEFAULT_NONE,
reply_to_message_id: Optional[int] = None,
reply_markup: Optional[ReplyMarkup] = None,
parse_mode: ODVInput[str] = DEFAULT_NONE,
allow_sending_without_reply: ODVInput[bool] = DEFAULT_NONE,
caption_entities: Optional[Sequence["MessageEntity"]] = None,
protect_content: ODVInput[bool] = DEFAULT_NONE,
message_thread_id: Optional[int] = None,
reply_parameters: Optional["ReplyParameters"] = None,
*,
reply_to_message_id: Optional[int] = None,
allow_sending_without_reply: ODVInput[bool] = DEFAULT_NONE,
filename: Optional[str] = None,
read_timeout: ODVInput[float] = DEFAULT_NONE,
write_timeout: ODVInput[float] = DEFAULT_NONE,
@ -1443,18 +1443,18 @@ class User(TelegramObject):
correct_option_id: Optional[CorrectOptionID] = None,
is_closed: Optional[bool] = None,
disable_notification: ODVInput[bool] = DEFAULT_NONE,
reply_to_message_id: Optional[int] = None,
reply_markup: Optional[ReplyMarkup] = None,
explanation: Optional[str] = None,
explanation_parse_mode: ODVInput[str] = DEFAULT_NONE,
open_period: Optional[int] = None,
close_date: Optional[Union[int, datetime]] = None,
allow_sending_without_reply: ODVInput[bool] = DEFAULT_NONE,
explanation_entities: Optional[Sequence["MessageEntity"]] = None,
protect_content: ODVInput[bool] = DEFAULT_NONE,
message_thread_id: Optional[int] = None,
reply_parameters: Optional["ReplyParameters"] = None,
*,
reply_to_message_id: Optional[int] = None,
allow_sending_without_reply: ODVInput[bool] = DEFAULT_NONE,
read_timeout: ODVInput[float] = DEFAULT_NONE,
write_timeout: ODVInput[float] = DEFAULT_NONE,
connect_timeout: ODVInput[float] = DEFAULT_NONE,
@ -1510,13 +1510,13 @@ class User(TelegramObject):
parse_mode: ODVInput[str] = DEFAULT_NONE,
caption_entities: Optional[Sequence["MessageEntity"]] = None,
disable_notification: ODVInput[bool] = DEFAULT_NONE,
reply_to_message_id: Optional[int] = None,
allow_sending_without_reply: ODVInput[bool] = DEFAULT_NONE,
reply_markup: Optional[ReplyMarkup] = None,
protect_content: ODVInput[bool] = DEFAULT_NONE,
message_thread_id: Optional[int] = None,
reply_parameters: Optional["ReplyParameters"] = None,
*,
reply_to_message_id: Optional[int] = None,
allow_sending_without_reply: ODVInput[bool] = DEFAULT_NONE,
read_timeout: ODVInput[float] = DEFAULT_NONE,
write_timeout: ODVInput[float] = DEFAULT_NONE,
connect_timeout: ODVInput[float] = DEFAULT_NONE,
@ -1565,13 +1565,13 @@ class User(TelegramObject):
parse_mode: ODVInput[str] = DEFAULT_NONE,
caption_entities: Optional[Sequence["MessageEntity"]] = None,
disable_notification: ODVInput[bool] = DEFAULT_NONE,
reply_to_message_id: Optional[int] = None,
allow_sending_without_reply: ODVInput[bool] = DEFAULT_NONE,
reply_markup: Optional[ReplyMarkup] = None,
protect_content: ODVInput[bool] = DEFAULT_NONE,
message_thread_id: Optional[int] = None,
reply_parameters: Optional["ReplyParameters"] = None,
*,
reply_to_message_id: Optional[int] = None,
allow_sending_without_reply: ODVInput[bool] = DEFAULT_NONE,
read_timeout: ODVInput[float] = DEFAULT_NONE,
write_timeout: ODVInput[float] = DEFAULT_NONE,
connect_timeout: ODVInput[float] = DEFAULT_NONE,

View file

@ -25,6 +25,9 @@ Warning:
"""
from typing import Optional, Sequence, Tuple, TypeVar
from telegram._linkpreviewoptions import LinkPreviewOptions
from telegram._utils.types import ODVInput
T = TypeVar("T")
@ -38,3 +41,21 @@ def parse_sequence_arg(arg: Optional[Sequence[T]]) -> Tuple[T, ...]:
:obj:`Tuple`: The sequence converted to a tuple or an empty tuple.
"""
return tuple(arg) if arg else ()
def parse_lpo_and_dwpp(
disable_web_page_preview: Optional[bool], link_preview_options: ODVInput[LinkPreviewOptions]
) -> ODVInput[LinkPreviewOptions]:
"""Wrapper around warn_about_deprecated_arg_return_new_arg. Takes care of converting
disable_web_page_preview to LinkPreviewOptions.
"""
if disable_web_page_preview and link_preview_options:
raise ValueError(
"Parameters `disable_web_page_preview` and `link_preview_options` are mutually "
"exclusive."
)
if disable_web_page_preview is not None:
link_preview_options = LinkPreviewOptions(is_disabled=disable_web_page_preview)
return link_preview_options

View file

@ -25,9 +25,6 @@ inside warnings.py.
"""
from typing import Any, Callable, Type
from telegram._linkpreviewoptions import LinkPreviewOptions
from telegram._utils.defaultvalue import DefaultValue
from telegram._utils.types import ODVInput
from telegram._utils.warnings import warn
from telegram.warnings import PTBDeprecationWarning
@ -93,28 +90,6 @@ def warn_about_deprecated_arg_return_new_arg(
return new_arg
def warn_for_link_preview_options(
disable_web_page_preview: ODVInput[bool], link_preview_options: ODVInput[LinkPreviewOptions]
) -> ODVInput[LinkPreviewOptions]:
"""Wrapper around warn_about_deprecated_arg_return_new_arg. Takes care of converting
disable_web_page_preview to LinkPreviewOptions.
"""
warn_about_deprecated_arg_return_new_arg(
deprecated_arg=disable_web_page_preview,
new_arg=link_preview_options,
deprecated_arg_name="disable_web_page_preview",
new_arg_name="link_preview_options",
bot_api_version="7.0",
stacklevel=2,
)
# Convert to LinkPreviewOptions:
if not isinstance(disable_web_page_preview, DefaultValue):
link_preview_options = LinkPreviewOptions(is_disabled=disable_web_page_preview)
return link_preview_options
def warn_about_deprecated_attr_in_property(
deprecated_attr_name: str,
new_attr_name: str,

View file

@ -558,10 +558,8 @@ class ExtBot(Bot, Generic[RLARGS]):
self,
endpoint: str,
data: JSONDict,
reply_to_message_id: Optional[int] = None,
disable_notification: ODVInput[bool] = DEFAULT_NONE,
reply_markup: Optional[ReplyMarkup] = None,
allow_sending_without_reply: ODVInput[bool] = DEFAULT_NONE,
protect_content: ODVInput[bool] = DEFAULT_NONE,
message_thread_id: Optional[int] = None,
caption: Optional[str] = None,
@ -570,6 +568,8 @@ class ExtBot(Bot, Generic[RLARGS]):
link_preview_options: ODVInput["LinkPreviewOptions"] = None,
reply_parameters: Optional["ReplyParameters"] = None,
*,
reply_to_message_id: Optional[int] = None,
allow_sending_without_reply: ODVInput[bool] = DEFAULT_NONE,
read_timeout: ODVInput[float] = DEFAULT_NONE,
write_timeout: ODVInput[float] = DEFAULT_NONE,
connect_timeout: ODVInput[float] = DEFAULT_NONE,
@ -767,13 +767,13 @@ class ExtBot(Bot, Generic[RLARGS]):
parse_mode: ODVInput[str] = DEFAULT_NONE,
caption_entities: Optional[Sequence["MessageEntity"]] = None,
disable_notification: ODVInput[bool] = DEFAULT_NONE,
reply_to_message_id: Optional[int] = None,
allow_sending_without_reply: ODVInput[bool] = DEFAULT_NONE,
reply_markup: Optional[ReplyMarkup] = None,
protect_content: ODVInput[bool] = DEFAULT_NONE,
message_thread_id: Optional[int] = None,
reply_parameters: Optional["ReplyParameters"] = None,
*,
reply_to_message_id: Optional[int] = None,
allow_sending_without_reply: ODVInput[bool] = DEFAULT_NONE,
read_timeout: ODVInput[float] = DEFAULT_NONE,
write_timeout: ODVInput[float] = DEFAULT_NONE,
connect_timeout: ODVInput[float] = DEFAULT_NONE,
@ -1603,11 +1603,11 @@ class ExtBot(Bot, Generic[RLARGS]):
message_id: Optional[int] = None,
inline_message_id: Optional[str] = None,
parse_mode: ODVInput[str] = DEFAULT_NONE,
disable_web_page_preview: ODVInput[bool] = DEFAULT_NONE,
reply_markup: Optional["InlineKeyboardMarkup"] = None,
entities: Optional[Sequence["MessageEntity"]] = None,
link_preview_options: ODVInput["LinkPreviewOptions"] = DEFAULT_NONE,
*,
disable_web_page_preview: Optional[bool] = None,
read_timeout: ODVInput[float] = DEFAULT_NONE,
write_timeout: ODVInput[float] = DEFAULT_NONE,
connect_timeout: ODVInput[float] = DEFAULT_NONE,
@ -2344,9 +2344,7 @@ class ExtBot(Bot, Generic[RLARGS]):
caption: Optional[str] = None,
parse_mode: ODVInput[str] = DEFAULT_NONE,
disable_notification: ODVInput[bool] = DEFAULT_NONE,
reply_to_message_id: Optional[int] = None,
reply_markup: Optional[ReplyMarkup] = None,
allow_sending_without_reply: ODVInput[bool] = DEFAULT_NONE,
caption_entities: Optional[Sequence["MessageEntity"]] = None,
protect_content: ODVInput[bool] = DEFAULT_NONE,
message_thread_id: Optional[int] = None,
@ -2354,6 +2352,8 @@ class ExtBot(Bot, Generic[RLARGS]):
thumbnail: Optional[FileInput] = None,
reply_parameters: Optional["ReplyParameters"] = None,
*,
reply_to_message_id: Optional[int] = None,
allow_sending_without_reply: ODVInput[bool] = DEFAULT_NONE,
filename: Optional[str] = None,
read_timeout: ODVInput[float] = DEFAULT_NONE,
write_timeout: ODVInput[float] = DEFAULT_NONE,
@ -2397,16 +2397,16 @@ class ExtBot(Bot, Generic[RLARGS]):
title: Optional[str] = None,
caption: Optional[str] = None,
disable_notification: ODVInput[bool] = DEFAULT_NONE,
reply_to_message_id: Optional[int] = None,
reply_markup: Optional[ReplyMarkup] = None,
parse_mode: ODVInput[str] = DEFAULT_NONE,
allow_sending_without_reply: ODVInput[bool] = DEFAULT_NONE,
caption_entities: Optional[Sequence["MessageEntity"]] = None,
protect_content: ODVInput[bool] = DEFAULT_NONE,
message_thread_id: Optional[int] = None,
thumbnail: Optional[FileInput] = None,
reply_parameters: Optional["ReplyParameters"] = None,
*,
reply_to_message_id: Optional[int] = None,
allow_sending_without_reply: ODVInput[bool] = DEFAULT_NONE,
filename: Optional[str] = None,
read_timeout: ODVInput[float] = DEFAULT_NONE,
write_timeout: ODVInput[float] = DEFAULT_NONE,
@ -2471,14 +2471,14 @@ class ExtBot(Bot, Generic[RLARGS]):
first_name: Optional[str] = None,
last_name: Optional[str] = None,
disable_notification: ODVInput[bool] = DEFAULT_NONE,
reply_to_message_id: Optional[int] = None,
reply_markup: Optional[ReplyMarkup] = None,
vcard: Optional[str] = None,
allow_sending_without_reply: ODVInput[bool] = DEFAULT_NONE,
protect_content: ODVInput[bool] = DEFAULT_NONE,
message_thread_id: Optional[int] = None,
reply_parameters: Optional["ReplyParameters"] = None,
*,
reply_to_message_id: Optional[int] = None,
allow_sending_without_reply: ODVInput[bool] = DEFAULT_NONE,
contact: Optional[Contact] = None,
read_timeout: ODVInput[float] = DEFAULT_NONE,
write_timeout: ODVInput[float] = DEFAULT_NONE,
@ -2512,14 +2512,14 @@ class ExtBot(Bot, Generic[RLARGS]):
self,
chat_id: Union[int, str],
disable_notification: ODVInput[bool] = DEFAULT_NONE,
reply_to_message_id: Optional[int] = None,
reply_markup: Optional[ReplyMarkup] = None,
emoji: Optional[str] = None,
allow_sending_without_reply: ODVInput[bool] = DEFAULT_NONE,
protect_content: ODVInput[bool] = DEFAULT_NONE,
message_thread_id: Optional[int] = None,
reply_parameters: Optional["ReplyParameters"] = None,
*,
reply_to_message_id: Optional[int] = None,
allow_sending_without_reply: ODVInput[bool] = DEFAULT_NONE,
read_timeout: ODVInput[float] = DEFAULT_NONE,
write_timeout: ODVInput[float] = DEFAULT_NONE,
connect_timeout: ODVInput[float] = DEFAULT_NONE,
@ -2550,17 +2550,17 @@ class ExtBot(Bot, Generic[RLARGS]):
document: Union[FileInput, "Document"],
caption: Optional[str] = None,
disable_notification: ODVInput[bool] = DEFAULT_NONE,
reply_to_message_id: Optional[int] = None,
reply_markup: Optional[ReplyMarkup] = None,
parse_mode: ODVInput[str] = DEFAULT_NONE,
disable_content_type_detection: Optional[bool] = None,
allow_sending_without_reply: ODVInput[bool] = DEFAULT_NONE,
caption_entities: Optional[Sequence["MessageEntity"]] = None,
protect_content: ODVInput[bool] = DEFAULT_NONE,
message_thread_id: Optional[int] = None,
thumbnail: Optional[FileInput] = None,
reply_parameters: Optional["ReplyParameters"] = None,
*,
reply_to_message_id: Optional[int] = None,
allow_sending_without_reply: ODVInput[bool] = DEFAULT_NONE,
filename: Optional[str] = None,
read_timeout: ODVInput[float] = DEFAULT_NONE,
write_timeout: ODVInput[float] = DEFAULT_NONE,
@ -2597,13 +2597,13 @@ class ExtBot(Bot, Generic[RLARGS]):
chat_id: int,
game_short_name: str,
disable_notification: ODVInput[bool] = DEFAULT_NONE,
reply_to_message_id: Optional[int] = None,
reply_markup: Optional["InlineKeyboardMarkup"] = None,
allow_sending_without_reply: ODVInput[bool] = DEFAULT_NONE,
protect_content: ODVInput[bool] = DEFAULT_NONE,
message_thread_id: Optional[int] = None,
reply_parameters: Optional["ReplyParameters"] = None,
*,
reply_to_message_id: Optional[int] = None,
allow_sending_without_reply: ODVInput[bool] = DEFAULT_NONE,
read_timeout: ODVInput[float] = DEFAULT_NONE,
write_timeout: ODVInput[float] = DEFAULT_NONE,
connect_timeout: ODVInput[float] = DEFAULT_NONE,
@ -2648,18 +2648,18 @@ class ExtBot(Bot, Generic[RLARGS]):
need_shipping_address: Optional[bool] = None,
is_flexible: Optional[bool] = None,
disable_notification: ODVInput[bool] = DEFAULT_NONE,
reply_to_message_id: Optional[int] = None,
reply_markup: Optional["InlineKeyboardMarkup"] = None,
provider_data: Optional[Union[str, object]] = None,
send_phone_number_to_provider: Optional[bool] = None,
send_email_to_provider: Optional[bool] = None,
allow_sending_without_reply: ODVInput[bool] = DEFAULT_NONE,
max_tip_amount: Optional[int] = None,
suggested_tip_amounts: Optional[Sequence[int]] = None,
protect_content: ODVInput[bool] = DEFAULT_NONE,
message_thread_id: Optional[int] = None,
reply_parameters: Optional["ReplyParameters"] = None,
*,
reply_to_message_id: Optional[int] = None,
allow_sending_without_reply: ODVInput[bool] = DEFAULT_NONE,
read_timeout: ODVInput[float] = DEFAULT_NONE,
write_timeout: ODVInput[float] = DEFAULT_NONE,
connect_timeout: ODVInput[float] = DEFAULT_NONE,
@ -2710,17 +2710,17 @@ class ExtBot(Bot, Generic[RLARGS]):
latitude: Optional[float] = None,
longitude: Optional[float] = None,
disable_notification: ODVInput[bool] = DEFAULT_NONE,
reply_to_message_id: Optional[int] = None,
reply_markup: Optional[ReplyMarkup] = None,
live_period: Optional[int] = None,
horizontal_accuracy: Optional[float] = None,
heading: Optional[int] = None,
proximity_alert_radius: Optional[int] = None,
allow_sending_without_reply: ODVInput[bool] = DEFAULT_NONE,
protect_content: ODVInput[bool] = DEFAULT_NONE,
message_thread_id: Optional[int] = None,
reply_parameters: Optional["ReplyParameters"] = None,
*,
reply_to_message_id: Optional[int] = None,
allow_sending_without_reply: ODVInput[bool] = DEFAULT_NONE,
location: Optional[Location] = None,
read_timeout: ODVInput[float] = DEFAULT_NONE,
write_timeout: ODVInput[float] = DEFAULT_NONE,
@ -2759,12 +2759,12 @@ class ExtBot(Bot, Generic[RLARGS]):
Union["InputMediaAudio", "InputMediaDocument", "InputMediaPhoto", "InputMediaVideo"]
],
disable_notification: ODVInput[bool] = DEFAULT_NONE,
reply_to_message_id: Optional[int] = None,
allow_sending_without_reply: ODVInput[bool] = DEFAULT_NONE,
protect_content: ODVInput[bool] = DEFAULT_NONE,
message_thread_id: Optional[int] = None,
reply_parameters: Optional["ReplyParameters"] = None,
*,
reply_to_message_id: Optional[int] = None,
allow_sending_without_reply: ODVInput[bool] = DEFAULT_NONE,
read_timeout: ODVInput[float] = DEFAULT_NONE,
write_timeout: ODVInput[float] = DEFAULT_NONE,
connect_timeout: ODVInput[float] = DEFAULT_NONE,
@ -2800,16 +2800,16 @@ class ExtBot(Bot, Generic[RLARGS]):
text: str,
parse_mode: ODVInput[str] = DEFAULT_NONE,
entities: Optional[Sequence["MessageEntity"]] = None,
disable_web_page_preview: ODVInput[bool] = DEFAULT_NONE,
disable_notification: ODVInput[bool] = DEFAULT_NONE,
protect_content: ODVInput[bool] = DEFAULT_NONE,
reply_to_message_id: Optional[int] = None,
allow_sending_without_reply: ODVInput[bool] = DEFAULT_NONE,
reply_markup: Optional[ReplyMarkup] = None,
message_thread_id: Optional[int] = None,
link_preview_options: ODVInput["LinkPreviewOptions"] = DEFAULT_NONE,
reply_parameters: Optional["ReplyParameters"] = None,
*,
disable_web_page_preview: Optional[bool] = None,
reply_to_message_id: Optional[int] = None,
allow_sending_without_reply: ODVInput[bool] = DEFAULT_NONE,
read_timeout: ODVInput[float] = DEFAULT_NONE,
write_timeout: ODVInput[float] = DEFAULT_NONE,
connect_timeout: ODVInput[float] = DEFAULT_NONE,
@ -2844,16 +2844,16 @@ class ExtBot(Bot, Generic[RLARGS]):
photo: Union[FileInput, "PhotoSize"],
caption: Optional[str] = None,
disable_notification: ODVInput[bool] = DEFAULT_NONE,
reply_to_message_id: Optional[int] = None,
reply_markup: Optional[ReplyMarkup] = None,
parse_mode: ODVInput[str] = DEFAULT_NONE,
allow_sending_without_reply: ODVInput[bool] = DEFAULT_NONE,
caption_entities: Optional[Sequence["MessageEntity"]] = None,
protect_content: ODVInput[bool] = DEFAULT_NONE,
message_thread_id: Optional[int] = None,
has_spoiler: Optional[bool] = None,
reply_parameters: Optional["ReplyParameters"] = None,
*,
reply_to_message_id: Optional[int] = None,
allow_sending_without_reply: ODVInput[bool] = DEFAULT_NONE,
filename: Optional[str] = None,
read_timeout: ODVInput[float] = DEFAULT_NONE,
write_timeout: ODVInput[float] = DEFAULT_NONE,
@ -2895,18 +2895,18 @@ class ExtBot(Bot, Generic[RLARGS]):
correct_option_id: Optional[CorrectOptionID] = None,
is_closed: Optional[bool] = None,
disable_notification: ODVInput[bool] = DEFAULT_NONE,
reply_to_message_id: Optional[int] = None,
reply_markup: Optional[ReplyMarkup] = None,
explanation: Optional[str] = None,
explanation_parse_mode: ODVInput[str] = DEFAULT_NONE,
open_period: Optional[int] = None,
close_date: Optional[Union[int, datetime]] = None,
allow_sending_without_reply: ODVInput[bool] = DEFAULT_NONE,
explanation_entities: Optional[Sequence["MessageEntity"]] = None,
protect_content: ODVInput[bool] = DEFAULT_NONE,
message_thread_id: Optional[int] = None,
reply_parameters: Optional["ReplyParameters"] = None,
*,
reply_to_message_id: Optional[int] = None,
allow_sending_without_reply: ODVInput[bool] = DEFAULT_NONE,
read_timeout: ODVInput[float] = DEFAULT_NONE,
write_timeout: ODVInput[float] = DEFAULT_NONE,
connect_timeout: ODVInput[float] = DEFAULT_NONE,
@ -2947,14 +2947,14 @@ class ExtBot(Bot, Generic[RLARGS]):
chat_id: Union[int, str],
sticker: Union[FileInput, "Sticker"],
disable_notification: ODVInput[bool] = DEFAULT_NONE,
reply_to_message_id: Optional[int] = None,
reply_markup: Optional[ReplyMarkup] = None,
allow_sending_without_reply: ODVInput[bool] = DEFAULT_NONE,
protect_content: ODVInput[bool] = DEFAULT_NONE,
message_thread_id: Optional[int] = None,
emoji: Optional[str] = None,
reply_parameters: Optional["ReplyParameters"] = None,
*,
reply_to_message_id: Optional[int] = None,
allow_sending_without_reply: ODVInput[bool] = DEFAULT_NONE,
read_timeout: ODVInput[float] = DEFAULT_NONE,
write_timeout: ODVInput[float] = DEFAULT_NONE,
connect_timeout: ODVInput[float] = DEFAULT_NONE,
@ -2989,16 +2989,16 @@ class ExtBot(Bot, Generic[RLARGS]):
address: Optional[str] = None,
foursquare_id: Optional[str] = None,
disable_notification: ODVInput[bool] = DEFAULT_NONE,
reply_to_message_id: Optional[int] = None,
reply_markup: Optional[ReplyMarkup] = None,
foursquare_type: Optional[str] = None,
google_place_id: Optional[str] = None,
google_place_type: Optional[str] = None,
allow_sending_without_reply: ODVInput[bool] = DEFAULT_NONE,
protect_content: ODVInput[bool] = DEFAULT_NONE,
message_thread_id: Optional[int] = None,
reply_parameters: Optional["ReplyParameters"] = None,
*,
reply_to_message_id: Optional[int] = None,
allow_sending_without_reply: ODVInput[bool] = DEFAULT_NONE,
venue: Optional[Venue] = None,
read_timeout: ODVInput[float] = DEFAULT_NONE,
write_timeout: ODVInput[float] = DEFAULT_NONE,
@ -3039,13 +3039,11 @@ class ExtBot(Bot, Generic[RLARGS]):
duration: Optional[int] = None,
caption: Optional[str] = None,
disable_notification: ODVInput[bool] = DEFAULT_NONE,
reply_to_message_id: Optional[int] = None,
reply_markup: Optional[ReplyMarkup] = None,
width: Optional[int] = None,
height: Optional[int] = None,
parse_mode: ODVInput[str] = DEFAULT_NONE,
supports_streaming: Optional[bool] = None,
allow_sending_without_reply: ODVInput[bool] = DEFAULT_NONE,
caption_entities: Optional[Sequence["MessageEntity"]] = None,
protect_content: ODVInput[bool] = DEFAULT_NONE,
message_thread_id: Optional[int] = None,
@ -3053,6 +3051,8 @@ class ExtBot(Bot, Generic[RLARGS]):
thumbnail: Optional[FileInput] = None,
reply_parameters: Optional["ReplyParameters"] = None,
*,
reply_to_message_id: Optional[int] = None,
allow_sending_without_reply: ODVInput[bool] = DEFAULT_NONE,
filename: Optional[str] = None,
read_timeout: ODVInput[float] = DEFAULT_NONE,
write_timeout: ODVInput[float] = DEFAULT_NONE,
@ -3095,14 +3095,14 @@ class ExtBot(Bot, Generic[RLARGS]):
duration: Optional[int] = None,
length: Optional[int] = None,
disable_notification: ODVInput[bool] = DEFAULT_NONE,
reply_to_message_id: Optional[int] = None,
reply_markup: Optional[ReplyMarkup] = None,
allow_sending_without_reply: ODVInput[bool] = DEFAULT_NONE,
protect_content: ODVInput[bool] = DEFAULT_NONE,
message_thread_id: Optional[int] = None,
thumbnail: Optional[FileInput] = None,
reply_parameters: Optional["ReplyParameters"] = None,
*,
reply_to_message_id: Optional[int] = None,
allow_sending_without_reply: ODVInput[bool] = DEFAULT_NONE,
filename: Optional[str] = None,
read_timeout: ODVInput[float] = DEFAULT_NONE,
write_timeout: ODVInput[float] = DEFAULT_NONE,
@ -3139,15 +3139,15 @@ class ExtBot(Bot, Generic[RLARGS]):
duration: Optional[int] = None,
caption: Optional[str] = None,
disable_notification: ODVInput[bool] = DEFAULT_NONE,
reply_to_message_id: Optional[int] = None,
reply_markup: Optional[ReplyMarkup] = None,
parse_mode: ODVInput[str] = DEFAULT_NONE,
allow_sending_without_reply: ODVInput[bool] = DEFAULT_NONE,
caption_entities: Optional[Sequence["MessageEntity"]] = None,
protect_content: ODVInput[bool] = DEFAULT_NONE,
message_thread_id: Optional[int] = None,
reply_parameters: Optional["ReplyParameters"] = None,
*,
reply_to_message_id: Optional[int] = None,
allow_sending_without_reply: ODVInput[bool] = DEFAULT_NONE,
filename: Optional[str] = None,
read_timeout: ODVInput[float] = DEFAULT_NONE,
write_timeout: ODVInput[float] = DEFAULT_NONE,

View file

@ -1364,7 +1364,7 @@ FORWARDED = _Forwarded(name="filters.FORWARDED")
.. versionchanged:: 20.8
Now based on :attr:`telegram.Message.forward_origin` instead of
:attr:`telegram.Message.forward_date`.
``telegram.Message.forward_date``.
"""
@ -1379,8 +1379,8 @@ class ForwardedFrom(_ChatUserBaseFilter):
.. versionadded:: 13.5
.. versionchanged:: 20.8
Was previously based on :attr:`telegram.Message.forward_from` and
:attr:`telegram.Message.forward_from_chat`.
Was previously based on ``telegram.Message.forward_from`` and
``telegram.Message.forward_from_chat``.
Examples:
``MessageHandler(filters.ForwardedFrom(chat_id=1234), callback_method)``
@ -2146,15 +2146,19 @@ class StatusUpdate:
__slots__ = ()
def filter(self, message: Message) -> bool:
return bool(message.user_shared)
return bool(message.api_kwargs.get("user_shared"))
USER_SHARED = _UserShared(name="filters.StatusUpdate.USER_SHARED")
"""Messages that contain :attr:`telegram.Message.user_shared`.
"""Messages that contain ``"user_shared"`` in :attr:`telegram.TelegramObject.api_kwargs`.
Warning:
This will only catch the legacy :attr:`telegram.Message.user_shared` attribute, not the
This will only catch the legacy ``user_shared`` field, not the
new :attr:`telegram.Message.users_shared` attribute!
.. versionchanged:: NEXT.VERSION
Now relies on :attr:`telegram.TelegramObject.api_kwargs` as the native attribute
``Message.user_shared`` was removed.
.. versionadded:: 20.1
.. deprecated:: 20.8
Use :attr:`USERS_SHARED` instead.

View file

@ -20,7 +20,6 @@ import pytest
from telegram import InputTextMessageContent, LinkPreviewOptions, MessageEntity
from telegram.constants import ParseMode
from telegram.warnings import PTBDeprecationWarning
from tests.auxil.slots import mro_slots
@ -52,7 +51,6 @@ class TestInputTextMessageContentWithoutRequest(TestInputTextMessageContentBase)
def test_expected_values(self, input_text_message_content):
assert input_text_message_content.parse_mode == self.parse_mode
assert input_text_message_content.message_text == self.message_text
assert input_text_message_content.disable_web_page_preview == self.disable_web_page_preview
assert input_text_message_content.entities == tuple(self.entities)
assert input_text_message_content.link_preview_options == self.link_preview_options
@ -95,13 +93,11 @@ class TestInputTextMessageContentWithoutRequest(TestInputTextMessageContentBase)
assert hash(a) != hash(d)
def test_mutually_exclusive(self):
with pytest.raises(ValueError, match="'link_preview_options' in Bot API 7.0"):
with pytest.raises(ValueError, match="`link_preview_options` are mutually exclusive"):
InputTextMessageContent(
"text", disable_web_page_preview=True, link_preview_options=LinkPreviewOptions()
)
def test_disable_web_page_preview_deprecated(self):
with pytest.warns(
PTBDeprecationWarning, match="'disable_web_page_preview' to 'link_preview_options'"
):
InputTextMessageContent("text", disable_web_page_preview=True).disable_web_page_preview
def test_disable_web_page_preview_deprecation(self):
itmc = InputTextMessageContent("text", disable_web_page_preview=True)
assert itmc.link_preview_options.is_disabled is True

View file

@ -549,11 +549,9 @@ async def check_defaults_handling(
}
# We tested this for a long time, but Bot API 7.0 deprecated it in favor of
# reply_parameters. In the transition phase, both exist in a mutually exclusive
# way. Testing both cases would require a lot of additional code, so we just
# ignore this parameter here until it is removed.
# Same for disable_web_page_preview
# way. Testing both cases would require a lot of additional code, so we for now are content
# with the explicit tests that we have inplace for allow_sending_without_reply
kwargs_need_default.discard("allow_sending_without_reply")
kwargs_need_default.discard("disable_web_page_preview")
if method.__name__.endswith("_media_group"):
# the parse_mode is applied to the first media item, and we test this elsewhere

View file

@ -1065,10 +1065,10 @@ class TestFilters:
assert filters.StatusUpdate.WRITE_ACCESS_ALLOWED.check_update(update)
update.message.write_access_allowed = None
update.message._user_shared = "user_shared"
update.message.api_kwargs = {"user_shared": "user_shared"}
assert filters.StatusUpdate.ALL.check_update(update)
assert filters.StatusUpdate.USER_SHARED.check_update(update)
update.message._user_shared = None
update.message.api_kwargs = {}
update.message.users_shared = "users_shared"
assert filters.StatusUpdate.ALL.check_update(update)

View file

@ -1061,12 +1061,12 @@ class TestBotWithoutRequest:
async def test_send_edit_message_mutually_exclusive_link_preview(self, bot, chat_id):
"""Test that link_preview is mutually exclusive with disable_web_page_preview."""
with pytest.raises(ValueError, match="'disable_web_page_preview' was renamed to"):
with pytest.raises(ValueError, match="`link_preview_options` are mutually exclusive"):
await bot.send_message(
chat_id, "text", disable_web_page_preview=True, link_preview_options="something"
)
with pytest.raises(ValueError, match="'disable_web_page_preview' was renamed to"):
with pytest.raises(ValueError, match="`link_preview_options` are mutually exclusive"):
await bot.edit_message_text(
"text", chat_id, 1, disable_web_page_preview=True, link_preview_options="something"
)
@ -2120,8 +2120,8 @@ class TestBotWithRequest:
)
assert forward_message.text == message.text
assert forward_message.forward_from.username == message.from_user.username
assert isinstance(forward_message.forward_date, dtm.datetime)
assert forward_message.forward_origin.sender_user == message.from_user
assert isinstance(forward_message.forward_origin.date, dtm.datetime)
async def test_forward_protected_message(self, bot, chat_id):
tasks = asyncio.gather(
@ -2155,7 +2155,7 @@ class TestBotWithRequest:
msg1, msg2 = await tasks
forward_messages = await bot.forward_messages(
chat_id, from_chat_id=chat_id, message_ids=(msg1.message_id, msg2.message_id)
chat_id, from_chat_id=chat_id, message_ids=sorted((msg1.message_id, msg2.message_id))
)
assert isinstance(forward_messages, tuple)
@ -2174,12 +2174,12 @@ class TestBotWithRequest:
forward_msg2 = temp_msg2.reply_to_message
assert forward_msg1.text == msg1.text
assert forward_msg1.forward_from.username == msg1.from_user.username
assert isinstance(forward_msg1.forward_date, dtm.datetime)
assert forward_msg1.forward_origin.sender_user == msg1.from_user
assert isinstance(forward_msg1.forward_origin.date, dtm.datetime)
assert forward_msg2.text == msg2.text
assert forward_msg2.forward_from.username == msg2.from_user.username
assert isinstance(forward_msg2.forward_date, dtm.datetime)
assert forward_msg2.forward_origin.sender_user == msg2.from_user
assert isinstance(forward_msg2.forward_origin.date, dtm.datetime)
async def test_delete_message(self, bot, chat_id):
message = await bot.send_message(chat_id, text="will be deleted")

View file

@ -23,11 +23,9 @@ from telegram import (
KeyboardButton,
KeyboardButtonPollType,
KeyboardButtonRequestChat,
KeyboardButtonRequestUser,
KeyboardButtonRequestUsers,
WebAppInfo,
)
from telegram.warnings import PTBDeprecationWarning
from tests.auxil.slots import mro_slots
@ -82,7 +80,8 @@ class TestKeyboardButtonWithoutRequest(TestKeyboardButtonBase):
assert keyboard_button_dict["request_chat"] == keyboard_button.request_chat.to_dict()
assert keyboard_button_dict["request_users"] == keyboard_button.request_users.to_dict()
def test_de_json(self, bot):
@pytest.mark.parametrize("request_user", [True, False])
def test_de_json(self, bot, request_user):
json_dict = {
"text": self.text,
"request_location": self.request_location,
@ -92,45 +91,26 @@ class TestKeyboardButtonWithoutRequest(TestKeyboardButtonBase):
"request_chat": self.request_chat.to_dict(),
"request_users": self.request_users.to_dict(),
}
if request_user:
json_dict["request_user"] = {"request_id": 2}
inline_keyboard_button = KeyboardButton.de_json(json_dict, None)
assert inline_keyboard_button.api_kwargs == {}
assert inline_keyboard_button.text == self.text
assert inline_keyboard_button.request_location == self.request_location
assert inline_keyboard_button.request_contact == self.request_contact
assert inline_keyboard_button.request_poll == self.request_poll
assert inline_keyboard_button.web_app == self.web_app
assert inline_keyboard_button.request_chat == self.request_chat
assert inline_keyboard_button.request_user == self.request_users
assert inline_keyboard_button.request_users == self.request_users
keyboard_button = KeyboardButton.de_json(json_dict, None)
if request_user:
assert keyboard_button.api_kwargs == {"request_user": {"request_id": 2}}
else:
assert keyboard_button.api_kwargs == {}
assert keyboard_button.text == self.text
assert keyboard_button.request_location == self.request_location
assert keyboard_button.request_contact == self.request_contact
assert keyboard_button.request_poll == self.request_poll
assert keyboard_button.web_app == self.web_app
assert keyboard_button.request_chat == self.request_chat
assert keyboard_button.request_users == self.request_users
none = KeyboardButton.de_json({}, None)
assert none is None
def test_request_user_deprecation_mutually_exclusive(self):
with pytest.raises(ValueError, match="'request_user' was renamed to 'request_users'"):
KeyboardButton(
"test",
request_users=KeyboardButtonRequestUsers(1),
request_user=KeyboardButtonRequestUsers(2),
)
def test_request_user_argument_deprecation_warning(self):
with pytest.warns(
PTBDeprecationWarning, match="'request_user' to 'request_users'"
) as record:
KeyboardButton("test", request_user=KeyboardButtonRequestUser(2))
assert record[0].filename == __file__, "wrong stacklevel"
def test_request_user_property_deprecation_warning(self, keyboard_button):
with pytest.warns(
PTBDeprecationWarning, match="'request_user' to 'request_users'"
) as record:
assert keyboard_button.request_user is keyboard_button.request_users
assert record[0].filename == __file__, "wrong stacklevel"
def test_equality(self):
a = KeyboardButton("test", request_contact=True)
b = KeyboardButton("test", request_contact=True)

View file

@ -16,17 +16,10 @@
#
# You should have received a copy of the GNU Lesser Public License
# along with this program. If not, see [http://www.gnu.org/licenses/].
import inspect
import pytest
from telegram import (
ChatAdministratorRights,
KeyboardButtonRequestChat,
KeyboardButtonRequestUser,
KeyboardButtonRequestUsers,
)
from telegram.warnings import PTBDeprecationWarning
from telegram import ChatAdministratorRights, KeyboardButtonRequestChat, KeyboardButtonRequestUsers
from tests.auxil.slots import mro_slots
@ -92,28 +85,6 @@ class TestKeyboardButtonRequestUsersWithoutRequest(TestKeyboardButtonRequestUser
assert hash(a) != hash(c)
class TestKeyboardButtonRequestUserWithoutRequest:
def test_slot_behaviour(self):
inst = KeyboardButtonRequestUser(1)
for attr in inst.__slots__:
assert getattr(inst, attr, "err") != "err", f"got extra slot '{attr}'"
assert len(mro_slots(inst)) == len(set(mro_slots(inst))), "duplicate slot"
def test_signature(self):
assert inspect.signature(KeyboardButtonRequestUser) == inspect.signature(
KeyboardButtonRequestUsers
)
def test_deprecation_warning(self):
with pytest.warns(
PTBDeprecationWarning,
match="'KeyboardButtonRequestUser' was renamed to 'KeyboardButtonRequestUsers'",
) as record:
KeyboardButtonRequestUser(request_id=1)
assert record[0].filename == __file__, "wrong stacklevel"
@pytest.fixture(scope="class")
def request_chat():
return KeyboardButtonRequestChat(

View file

@ -20,10 +20,9 @@ import datetime as dtm
import pytest
from telegram import Chat, InaccessibleMessage, MaybeInaccessibleMessage
from telegram import Chat, MaybeInaccessibleMessage
from telegram._utils.datetime import UTC, to_timestamp
from telegram.constants import ZERO_DATE
from telegram.warnings import PTBDeprecationWarning
from tests.auxil.slots import mro_slots
@ -111,29 +110,6 @@ class TestMaybeInaccessibleMessageWithoutRequest(TestMaybeInaccessibleMessageBas
assert MaybeInaccessibleMessage(self.chat, self.message_id, self.date).is_accessible
assert not MaybeInaccessibleMessage(self.chat, self.message_id, ZERO_DATE).is_accessible
def test_bool(self):
assert bool(MaybeInaccessibleMessage(self.chat, self.message_id, self.date).is_accessible)
assert not bool(
MaybeInaccessibleMessage(self.chat, self.message_id, ZERO_DATE).is_accessible
)
@pytest.mark.parametrize("cls", [MaybeInaccessibleMessage, InaccessibleMessage])
def test_bool_deprecation_warning(self, cls):
if cls is MaybeInaccessibleMessage:
args = (self.chat, self.message_id, self.date)
else:
args = (self.chat, self.message_id)
with pytest.warns(
PTBDeprecationWarning,
match=(
f"`{cls.__name__}.__bool__` will be reverted to Pythons default implementation"
),
) as record:
bool(cls(*args))
assert record[0].filename == __file__, "wrong stacklevel"
def test_equality(self, maybe_inaccessible_message):
a = maybe_inaccessible_message
b = MaybeInaccessibleMessage(

View file

@ -98,12 +98,6 @@ def message(bot):
@pytest.fixture(
params=[
{"forward_from": User(99, "forward_user", False), "forward_date": datetime.utcnow()},
{
"forward_from_chat": Chat(-23, "channel"),
"forward_from_message_id": 101,
"forward_date": datetime.utcnow(),
},
{
"reply_to_message": Message(
50, datetime.utcnow(), Chat(13, "channel"), User(9, "i", False)
@ -165,7 +159,6 @@ def message(bot):
)
},
{"connected_website": "http://example.com/"},
{"forward_signature": "some_forward_sign"},
{"author_signature": "some_author_sign"},
{
"photo": [PhotoSize("photo_id", "unique_id", 50, 50)],
@ -224,9 +217,6 @@ def message(bot):
},
{"web_app_data": WebAppData("some_data", "some_button_text")},
{"message_thread_id": 123},
# Using a `UserShared` object here doesn't work, because `to_dict` produces `user_ids`
# instead of `user_id` - but that's what we want to test here.
{"user_shared": {"request_id": 1, "user_id": 2}},
{"users_shared": UsersShared(1, [2, 3])},
{"chat_shared": ChatShared(3, 4)},
{
@ -271,8 +261,6 @@ def message(bot):
{"forward_origin": MessageOriginChat(datetime.utcnow(), Chat(1, Chat.PRIVATE))},
],
ids=[
"forwarded_user",
"forwarded_channel",
"reply",
"edited",
"text",
@ -305,7 +293,6 @@ def message(bot):
"invoice",
"successful_payment",
"connected_website",
"forward_signature",
"author_signature",
"photo_from_media_group",
"passport_data",
@ -324,7 +311,6 @@ def message(bot):
"entities",
"web_app_data",
"message_thread_id",
"user_shared",
"users_shared",
"chat_shared",
"giveaway",
@ -518,7 +504,6 @@ class TestMessageWithoutRequest(TestMessageBase):
"date": int(datetime.now().timestamp()),
"chat": None,
"edit_date": int(datetime.now().timestamp()),
"forward_date": int(datetime.now().timestamp()),
}
message_raw = Message.de_json(json_dict, raw_bot)
@ -534,11 +519,6 @@ class TestMessageWithoutRequest(TestMessageBase):
message_tz.edit_date.replace(tzinfo=None)
)
forward_date_offset = message_tz.forward_date.utcoffset()
forward_date_tz_bot_offset = tz_bot.defaults.tzinfo.utcoffset(
message_tz.forward_date.replace(tzinfo=None)
)
assert message_raw.date.tzinfo == UTC
assert message_bot.date.tzinfo == UTC
assert date_offset == date_tz_bot_offset
@ -547,9 +527,21 @@ class TestMessageWithoutRequest(TestMessageBase):
assert message_bot.edit_date.tzinfo == UTC
assert edit_date_offset == edit_date_tz_bot_offset
assert message_raw.forward_date.tzinfo == UTC
assert message_bot.forward_date.tzinfo == UTC
assert forward_date_offset == forward_date_tz_bot_offset
def test_de_json_api_kwargs_backward_compatibility(self, bot, message_params):
message_dict = message_params.to_dict()
keys = (
"user_shared",
"forward_from",
"forward_from_chat",
"forward_from_message_id",
"forward_signature",
"forward_sender_name",
"forward_date",
)
for key in keys:
message_dict[key] = key
message = Message.de_json(message_dict, bot)
assert message.api_kwargs == {key: key for key in keys}
def test_equality(self):
id_ = 1
@ -572,124 +564,6 @@ class TestMessageWithoutRequest(TestMessageBase):
assert a != e
assert hash(a) != hash(e)
def test_user_shared_init_deprecation(self, message):
with pytest.warns(
PTBDeprecationWarning, match="'user_shared' was renamed to 'users_shared'"
) as record:
Message(message_id=1, date=self.date, chat=self.chat, user_shared=1)
assert record[0].filename == __file__, "wrong stacklevel"
def test_user_shared_property_deprecation(self, message):
with pytest.warns(
PTBDeprecationWarning, match="'user_shared' to 'users_shared'"
) as record:
message.user_shared
assert record[0].filename == __file__, "wrong stacklevel"
def test_forward_from_init_deprecation(self, message):
with pytest.warns(
PTBDeprecationWarning, match="'forward_from' was transferred to 'forward_origin'"
) as record:
Message(
message_id=1, date=self.date, chat=self.chat, forward_from=User(1, "user", False)
)
assert record[0].filename == __file__, "wrong stacklevel"
def test_forward_from_property_deprecation(self, message):
with pytest.warns(
PTBDeprecationWarning, match="'forward_from' to 'forward_origin'"
) as record:
message.forward_from
assert record[0].filename == __file__, "wrong stacklevel"
def test_forward_from_chat_init_deprecation(self, message):
with pytest.warns(
PTBDeprecationWarning, match="'forward_from_chat' was transferred to 'forward_origin'"
) as record:
Message(
message_id=1, date=self.date, chat=self.chat, forward_from_chat=Chat(1, "private")
)
assert record[0].filename == __file__, "wrong stacklevel"
def test_forward_from_chat_property_deprecation(self, message):
with pytest.warns(
PTBDeprecationWarning, match="'forward_from_chat' to 'forward_origin'"
) as record:
message.forward_from_chat
assert record[0].filename == __file__, "wrong stacklevel"
def test_forward_from_message_id_init_deprecation(self, message):
with pytest.warns(
PTBDeprecationWarning,
match="'forward_from_message_id' was transferred to 'forward_origin'",
) as record:
Message(message_id=1, date=self.date, chat=self.chat, forward_from_message_id=1)
assert record[0].filename == __file__, "wrong stacklevel"
def test_forward_from_message_id_property_deprecation(self, message):
with pytest.warns(
PTBDeprecationWarning, match="'forward_from_message_id' to 'forward_origin'"
) as record:
message.forward_from_message_id
assert record[0].filename == __file__, "wrong stacklevel"
def test_forward_signature_init_deprecation(self, message):
with pytest.warns(
PTBDeprecationWarning, match="'forward_signature' was transferred to 'forward_origin'"
) as record:
Message(message_id=1, date=self.date, chat=self.chat, forward_signature="signature")
assert record[0].filename == __file__, "wrong stacklevel"
def test_forward_signature_property_deprecation(self, message):
with pytest.warns(
PTBDeprecationWarning, match="'forward_signature' to 'forward_origin'"
) as record:
message.forward_signature
assert record[0].filename == __file__, "wrong stacklevel"
def test_forward_sender_name_init_deprecation(self, message):
with pytest.warns(
PTBDeprecationWarning,
match="'forward_sender_name' was transferred to 'forward_origin'",
) as record:
Message(message_id=1, date=self.date, chat=self.chat, forward_sender_name="name")
assert record[0].filename == __file__, "wrong stacklevel"
def test_forward_sender_name_property_deprecation(self, message):
with pytest.warns(
PTBDeprecationWarning, match="'forward_sender_name' to 'forward_origin'"
) as record:
message.forward_sender_name
assert record[0].filename == __file__, "wrong stacklevel"
def test_forward_date_init_deprecation(self, message):
with pytest.warns(
PTBDeprecationWarning, match="'forward_date' was transferred to 'forward_origin'"
) as record:
Message(message_id=1, date=self.date, chat=self.chat, forward_date=datetime.utcnow())
assert record[0].filename == __file__, "wrong stacklevel"
def test_forward_date_property_deprecation(self, message):
with pytest.warns(
PTBDeprecationWarning, match="'forward_date' to 'forward_origin'"
) as record:
message.forward_date
assert record[0].filename == __file__, "wrong stacklevel"
def test_bool(self, message, recwarn):
# Relevant as long as we override MaybeInaccessibleMessage.__bool__
# Can be removed once that's removed

View file

@ -94,6 +94,13 @@ class ParamTypeCheckingExceptions:
PTB_EXTRA_PARAMS = {
"send_contact": {"contact"},
"send_location": {"location"},
"(send_message|edit_message_text)": { # convenience parameters
"disable_web_page_preview",
},
r"(send|copy)_\w+": { # convenience parameters
"reply_to_message_id",
"allow_sending_without_reply",
},
"edit_message_live_location": {"location"},
"send_venue": {"venue"},
"answer_inline_query": {"current_offset"},
@ -159,25 +166,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]] = {
# Deprecated by Bot API 7.0, kept for now for bw compat:
"KeyboardButton": {"request_user"},
"Message": {
"forward_from",
"forward_signature",
"forward_sender_name",
"forward_date",
"forward_from_chat",
"forward_from_message_id",
"user_shared",
},
"(send_message|edit_message_text)": {
"disable_web_page_preview",
"reply_to_message_id",
"allow_sending_without_reply",
},
r"copy_message|send_\w+": {"allow_sending_without_reply", "reply_to_message_id"},
}
BACKWARDS_COMPAT_KWARGS: dict[str, set[str]] = {}
def backwards_compat_kwargs(object_name: str) -> set[str]:

View file

@ -16,20 +16,13 @@
#
# You should have received a copy of the GNU Lesser Public License
# along with this program. If not, see [http://www.gnu.org/licenses/].
import inspect
import pytest
from telegram import ChatShared, UserShared, UsersShared
from telegram.warnings import PTBDeprecationWarning
from telegram import ChatShared, UsersShared
from tests.auxil.slots import mro_slots
@pytest.fixture(scope="class")
def user_shared():
return UserShared(TestUsersSharedBase.request_id, TestUsersSharedBase.user_id)
@pytest.fixture(scope="class")
def users_shared():
return UsersShared(TestUsersSharedBase.request_id, TestUsersSharedBase.user_ids)
@ -82,75 +75,6 @@ class TestUsersSharedWithoutRequest(TestUsersSharedBase):
assert hash(a) != hash(d)
class TestUserSharedWithoutRequest(TestUsersSharedBase):
def test_slot_behaviour(self, user_shared):
for attr in user_shared.__slots__:
assert getattr(user_shared, attr, "err") != "err", f"got extra slot '{attr}'"
assert len(mro_slots(user_shared)) == len(set(mro_slots(user_shared))), "duplicate slot"
def test_to_dict(self, user_shared):
user_shared_dict = user_shared.to_dict()
assert isinstance(user_shared_dict, dict)
assert user_shared_dict["request_id"] == self.request_id
assert user_shared_dict["user_ids"] == [self.user_id]
def test_de_json(self, bot):
json_dict = {
"request_id": self.request_id,
"user_id": self.user_id,
}
user_shared = UserShared.de_json(json_dict, bot)
assert user_shared.api_kwargs == {}
assert user_shared.request_id == self.request_id
assert user_shared.user_id == self.user_id
assert user_shared.user_ids == (self.user_id,)
def test_signature(self):
user_signature = inspect.signature(UserShared)
users_signature = inspect.signature(UsersShared)
assert user_signature.return_annotation == users_signature.return_annotation
for name, parameter in user_signature.parameters.items():
if name not in users_signature.parameters:
assert name == "user_id"
else:
assert parameter.annotation == users_signature.parameters[name].annotation
assert set(users_signature.parameters) - set(user_signature.parameters) == {"user_ids"}
def test_deprecation_warnings(self):
with pytest.warns(
PTBDeprecationWarning, match="'UserShared' was renamed to 'UsersShared'"
) as record:
user_shared = UserShared(request_id=1, user_id=1)
assert record[0].filename == __file__, "wrong stacklevel"
with pytest.warns(PTBDeprecationWarning, match="'user_id' to 'user_ids'") as record:
user_shared.user_id
assert record[0].filename == __file__, "wrong stacklevel"
def test_equality(self):
a = UserShared(self.request_id, self.user_id)
b = UserShared(self.request_id, self.user_id)
c = UserShared(1, self.user_id)
d = UserShared(self.request_id, 1)
assert a == b
assert hash(a) == hash(b)
assert a is not b
assert a != c
assert hash(a) != hash(c)
assert a != d
assert hash(a) != hash(d)
@pytest.fixture(scope="class")
def chat_shared():
return ChatShared(