From 10f97f82a0a1b42c8566d7ed459deeb2b81a98a5 Mon Sep 17 00:00:00 2001 From: latan Date: Mon, 20 Mar 2023 23:17:14 +0200 Subject: [PATCH 1/5] Renamed the parameter thumb in the methods sendAnimation, sendAudio, sendDocument, sendVideo, sendVideoNote to thumbnail. --- aiogram/bot/bot.py | 51 +++++++++++++++++++++++++++++++++------------- 1 file changed, 37 insertions(+), 14 deletions(-) diff --git a/aiogram/bot/bot.py b/aiogram/bot/bot.py index e0951a9e..34cd916e 100644 --- a/aiogram/bot/bot.py +++ b/aiogram/bot/bot.py @@ -574,7 +574,7 @@ class Bot(BaseBot, DataMixin, ContextInstanceMixin): duration: typing.Optional[base.Integer] = None, performer: typing.Optional[base.String] = None, title: typing.Optional[base.String] = None, - thumb: typing.Union[base.InputFile, base.String, None] = None, + thumbnail: typing.Union[base.InputFile, base.String, None] = None, message_thread_id: typing.Optional[base.Integer] = None, disable_notification: typing.Optional[base.Boolean] = None, protect_content: typing.Optional[base.Boolean] = None, @@ -584,6 +584,7 @@ class Bot(BaseBot, DataMixin, ContextInstanceMixin): types.ReplyKeyboardMarkup, types.ReplyKeyboardRemove, types.ForceReply, None] = None, + thumb: typing.Union[base.InputFile, base.String, None] = None, ) -> types.Message: """ Use this method to send audio files, if you want Telegram clients to display them in the music player. @@ -623,9 +624,13 @@ class Bot(BaseBot, DataMixin, ContextInstanceMixin): :param title: Track name :type title: :obj:`typing.Optional[base.String]` + :param thumb: Thumbnail of the file sent :type thumb: :obj:`typing.Union[base.InputFile, base.String, None]` + :param thumbnail: Thumbnail of the file sent + :type thumbnail: :obj:`typing.Union[base.InputFile, base.String, None]` + :param disable_notification: Sends the message silently. Users will receive a notification with no sound :type disable_notification: :obj:`typing.Optional[base.Boolean]` @@ -650,7 +655,7 @@ class Bot(BaseBot, DataMixin, ContextInstanceMixin): """ reply_markup = prepare_arg(reply_markup) caption_entities = prepare_arg(caption_entities) - payload = generate_payload(**locals(), exclude=['audio', 'thumb']) + payload = generate_payload(**locals(), exclude=['audio', 'thumb', 'thumbnail']) if self.parse_mode and caption_entities is None: payload.setdefault('parse_mode', self.parse_mode) if self.protect_content is not None: @@ -658,7 +663,7 @@ class Bot(BaseBot, DataMixin, ContextInstanceMixin): files = {} prepare_file(payload, files, 'audio', audio) - prepare_attachment(payload, files, 'thumb', thumb) + prepare_attachment(payload, files, 'thumbnail', thumbnail or thumb) result = await self.request(api.Methods.SEND_AUDIO, payload, files) return types.Message(**result) @@ -666,7 +671,7 @@ class Bot(BaseBot, DataMixin, ContextInstanceMixin): async def send_document(self, chat_id: typing.Union[base.Integer, base.String], document: typing.Union[base.InputFile, base.String], - thumb: typing.Union[base.InputFile, base.String, None] = None, + thumbnail: typing.Union[base.InputFile, base.String, None] = None, caption: typing.Optional[base.String] = None, parse_mode: typing.Optional[base.String] = None, caption_entities: typing.Optional[typing.List[types.MessageEntity]] = None, @@ -681,6 +686,7 @@ class Bot(BaseBot, DataMixin, ContextInstanceMixin): types.ReplyKeyboardRemove, types.ForceReply, None] = None, + thumb: typing.Union[base.InputFile, base.String, None] = None, ) -> types.Message: """ Use this method to send general files. On success, the sent Message is @@ -701,6 +707,9 @@ class Bot(BaseBot, DataMixin, ContextInstanceMixin): :param document: File to send :type document: :obj:`typing.Union[base.InputFile, base.String]` + :param thumbnail: Thumbnail of the file sent + :type thumbnail: :obj:`typing.Union[base.InputFile, base.String, None]` + :param thumb: Thumbnail of the file sent :type thumb: :obj:`typing.Union[base.InputFile, base.String, None]` @@ -748,7 +757,7 @@ class Bot(BaseBot, DataMixin, ContextInstanceMixin): """ reply_markup = prepare_arg(reply_markup) caption_entities = prepare_arg(caption_entities) - payload = generate_payload(**locals(), exclude=['document']) + payload = generate_payload(**locals(), exclude=['document', 'thumb', 'thumbnail']) if self.parse_mode and caption_entities is None: payload.setdefault('parse_mode', self.parse_mode) if self.protect_content is not None: @@ -756,7 +765,7 @@ class Bot(BaseBot, DataMixin, ContextInstanceMixin): files = {} prepare_file(payload, files, 'document', document) - prepare_attachment(payload, files, 'thumb', thumb) + prepare_attachment(payload, files, 'thumbnail', thumbnail or thumb) result = await self.request(api.Methods.SEND_DOCUMENT, payload, files) return types.Message(**result) @@ -766,7 +775,7 @@ class Bot(BaseBot, DataMixin, ContextInstanceMixin): duration: typing.Optional[base.Integer] = None, width: typing.Optional[base.Integer] = None, height: typing.Optional[base.Integer] = None, - thumb: typing.Union[base.InputFile, base.String, None] = None, + thumbnail: typing.Union[base.InputFile, base.String, None] = None, caption: typing.Optional[base.String] = None, parse_mode: typing.Optional[base.String] = None, caption_entities: typing.Optional[typing.List[types.MessageEntity]] = None, @@ -781,6 +790,7 @@ class Bot(BaseBot, DataMixin, ContextInstanceMixin): types.ReplyKeyboardRemove, types.ForceReply, None] = None, has_spoiler: typing.Optional[base.Boolean] = None, + thumb: typing.Union[base.InputFile, base.String, None] = None, ) -> types.Message: """ Use this method to send video files, Telegram clients support mp4 videos @@ -807,6 +817,9 @@ class Bot(BaseBot, DataMixin, ContextInstanceMixin): :param height: Video height :type height: :obj:`typing.Optional[base.Integer]` + :param thumbnail: Thumbnail of the file sent + :type thumbnail: :obj:`typing.Union[base.InputFile, base.String, None]` + :param thumb: Thumbnail of the file sent :type thumb: :obj:`typing.Union[base.InputFile, base.String, None]` @@ -851,7 +864,7 @@ class Bot(BaseBot, DataMixin, ContextInstanceMixin): """ reply_markup = prepare_arg(reply_markup) caption_entities = prepare_arg(caption_entities) - payload = generate_payload(**locals(), exclude=['video', 'thumb']) + payload = generate_payload(**locals(), exclude=['video', 'thumb', 'thumbnail']) if self.parse_mode and caption_entities is None: payload.setdefault('parse_mode', self.parse_mode) if self.protect_content is not None: @@ -859,7 +872,7 @@ class Bot(BaseBot, DataMixin, ContextInstanceMixin): files = {} prepare_file(payload, files, 'video', video) - prepare_attachment(payload, files, 'thumb', thumb) + prepare_attachment(payload, files, 'thumbnail', thumbnail or thumb) result = await self.request(api.Methods.SEND_VIDEO, payload, files) return types.Message(**result) @@ -870,7 +883,7 @@ class Bot(BaseBot, DataMixin, ContextInstanceMixin): duration: typing.Optional[base.Integer] = None, width: typing.Optional[base.Integer] = None, height: typing.Optional[base.Integer] = None, - thumb: typing.Union[typing.Union[base.InputFile, base.String], None] = None, + thumbnail: typing.Union[typing.Union[base.InputFile, base.String], None] = None, caption: typing.Optional[base.String] = None, parse_mode: typing.Optional[base.String] = None, caption_entities: typing.Optional[typing.List[types.MessageEntity]] = None, @@ -884,6 +897,7 @@ class Bot(BaseBot, DataMixin, ContextInstanceMixin): types.ReplyKeyboardRemove, types.ForceReply], None] = None, has_spoiler: typing.Optional[base.Boolean] = None, + thumb: typing.Union[typing.Union[base.InputFile, base.String], None] = None, ) -> types.Message: """ Use this method to send animation files (GIF or H.264/MPEG-4 AVC video without sound). @@ -915,6 +929,10 @@ class Bot(BaseBot, DataMixin, ContextInstanceMixin): :param height: Animation height :type height: :obj:`typing.Optional[base.Integer]` + :param thumbnail: Thumbnail of the file sent. The thumbnail should be in JPEG format and less than 200 kB in size. + A thumbnail‘s width and height should not exceed 320. + :type thumbnail: :obj:`typing.Union[typing.Union[base.InputFile, base.String], None]` + :param thumb: Thumbnail of the file sent. The thumbnail should be in JPEG format and less than 200 kB in size. A thumbnail‘s width and height should not exceed 320. :type thumb: :obj:`typing.Union[typing.Union[base.InputFile, base.String], None]` @@ -957,7 +975,7 @@ class Bot(BaseBot, DataMixin, ContextInstanceMixin): """ reply_markup = prepare_arg(reply_markup) caption_entities = prepare_arg(caption_entities) - payload = generate_payload(**locals(), exclude=["animation", "thumb"]) + payload = generate_payload(**locals(), exclude=["animation", "thumbnail", "thumb"]) if self.parse_mode and caption_entities is None: payload.setdefault('parse_mode', self.parse_mode) if self.protect_content is not None: @@ -965,7 +983,7 @@ class Bot(BaseBot, DataMixin, ContextInstanceMixin): files = {} prepare_file(payload, files, 'animation', animation) - prepare_attachment(payload, files, 'thumb', thumb) + prepare_attachment(payload, files, 'thumbnail', thumbnail or thumb) result = await self.request(api.Methods.SEND_ANIMATION, payload, files) return types.Message(**result) @@ -1060,7 +1078,7 @@ class Bot(BaseBot, DataMixin, ContextInstanceMixin): video_note: typing.Union[base.InputFile, base.String], duration: typing.Optional[base.Integer] = None, length: typing.Optional[base.Integer] = None, - thumb: typing.Union[base.InputFile, base.String, None] = None, + thumbnail: typing.Union[base.InputFile, base.String, None] = None, message_thread_id: typing.Optional[base.Integer] = None, disable_notification: typing.Optional[base.Boolean] = None, protect_content: typing.Optional[base.Boolean] = None, @@ -1070,6 +1088,7 @@ class Bot(BaseBot, DataMixin, ContextInstanceMixin): types.ReplyKeyboardMarkup, types.ReplyKeyboardRemove, types.ForceReply, None] = None, + thumb: typing.Union[base.InputFile, base.String, None] = None, ) -> types.Message: """ As of v.4.0, Telegram clients support rounded square mp4 videos of up to 1 minute long. @@ -1093,6 +1112,9 @@ class Bot(BaseBot, DataMixin, ContextInstanceMixin): :param length: Video width and height :type length: :obj:`typing.Optional[base.Integer]` + :param thumbnail: Thumbnail of the file sent + :type thumbnail: :obj:`typing.Union[base.InputFile, base.String, None]` + :param thumb: Thumbnail of the file sent :type thumb: :obj:`typing.Union[base.InputFile, base.String, None]` @@ -1119,12 +1141,13 @@ class Bot(BaseBot, DataMixin, ContextInstanceMixin): :rtype: :obj:`types.Message` """ reply_markup = prepare_arg(reply_markup) - payload = generate_payload(**locals(), exclude=['video_note']) + payload = generate_payload(**locals(), exclude=['video_note', 'thumb', 'thumbnail']) if self.protect_content is not None: payload.setdefault('protect_content', self.protect_content) files = {} prepare_file(payload, files, 'video_note', video_note) + prepare_file(payload, files, 'thumbnail', thumbnail) result = await self.request(api.Methods.SEND_VIDEO_NOTE, payload, files) return types.Message(**result) From d4b3f58b88d136efc36357dea6925c546c390f14 Mon Sep 17 00:00:00 2001 From: latan Date: Tue, 21 Mar 2023 09:36:23 +0200 Subject: [PATCH 2/5] Add deprecated warning for thumb arguments --- aiogram/bot/bot.py | 27 ++++++++++++++++++++------- 1 file changed, 20 insertions(+), 7 deletions(-) diff --git a/aiogram/bot/bot.py b/aiogram/bot/bot.py index 34cd916e..ccc342d1 100644 --- a/aiogram/bot/bot.py +++ b/aiogram/bot/bot.py @@ -8,7 +8,7 @@ import warnings from .base import BaseBot, api from .. import types from ..types import base -from ..utils.deprecated import deprecated +from ..utils.deprecated import deprecated, renamed_argument from ..utils.exceptions import ValidationError from ..utils.mixins import DataMixin, ContextInstanceMixin from ..utils.payload import generate_payload, prepare_arg, prepare_attachment, prepare_file @@ -565,6 +565,7 @@ class Bot(BaseBot, DataMixin, ContextInstanceMixin): result = await self.request(api.Methods.SEND_PHOTO, payload, files) return types.Message(**result) + @renamed_argument('thumb', 'thumbnail', '3.0') async def send_audio(self, chat_id: typing.Union[base.Integer, base.String], audio: typing.Union[base.InputFile, base.String], @@ -625,7 +626,7 @@ class Bot(BaseBot, DataMixin, ContextInstanceMixin): :type title: :obj:`typing.Optional[base.String]` - :param thumb: Thumbnail of the file sent + :param thumb: deprecated in API 6.6. Use thumbnail instead :type thumb: :obj:`typing.Union[base.InputFile, base.String, None]` :param thumbnail: Thumbnail of the file sent @@ -660,6 +661,15 @@ class Bot(BaseBot, DataMixin, ContextInstanceMixin): payload.setdefault('parse_mode', self.parse_mode) if self.protect_content is not None: payload.setdefault('protect_content', self.protect_content) + deprecated_list = [thumb] + for param in deprecated_list: + if param is None: + warnings.warn( + message=f"The parameter `{param}` deprecated, use updated method params instead.", + category=DeprecationWarning, + stacklevel=2 + ) + files = {} prepare_file(payload, files, 'audio', audio) @@ -668,6 +678,7 @@ class Bot(BaseBot, DataMixin, ContextInstanceMixin): result = await self.request(api.Methods.SEND_AUDIO, payload, files) return types.Message(**result) + @renamed_argument('thumb', 'thumbnail', '3.0') async def send_document(self, chat_id: typing.Union[base.Integer, base.String], document: typing.Union[base.InputFile, base.String], @@ -710,7 +721,7 @@ class Bot(BaseBot, DataMixin, ContextInstanceMixin): :param thumbnail: Thumbnail of the file sent :type thumbnail: :obj:`typing.Union[base.InputFile, base.String, None]` - :param thumb: Thumbnail of the file sent + :param thumb: deprecated in API 6.6. Use thumbnail instead :type thumb: :obj:`typing.Union[base.InputFile, base.String, None]` :param caption: Document caption (may also be used when resending documents @@ -770,6 +781,7 @@ class Bot(BaseBot, DataMixin, ContextInstanceMixin): result = await self.request(api.Methods.SEND_DOCUMENT, payload, files) return types.Message(**result) + @renamed_argument('thumb', 'thumbnail', '6.6') async def send_video(self, chat_id: typing.Union[base.Integer, base.String], video: typing.Union[base.InputFile, base.String], duration: typing.Optional[base.Integer] = None, @@ -820,7 +832,7 @@ class Bot(BaseBot, DataMixin, ContextInstanceMixin): :param thumbnail: Thumbnail of the file sent :type thumbnail: :obj:`typing.Union[base.InputFile, base.String, None]` - :param thumb: Thumbnail of the file sent + :param thumb: deprecated in API 6.6, Use thumbnail instead :type thumb: :obj:`typing.Union[base.InputFile, base.String, None]` :param caption: Video caption (may also be used when resending videos by file_id), 0-1024 characters @@ -877,6 +889,7 @@ class Bot(BaseBot, DataMixin, ContextInstanceMixin): result = await self.request(api.Methods.SEND_VIDEO, payload, files) return types.Message(**result) + @renamed_argument('thumb', 'thumbnail', '3.0') async def send_animation(self, chat_id: typing.Union[base.Integer, base.String], animation: typing.Union[base.InputFile, base.String], @@ -933,8 +946,7 @@ class Bot(BaseBot, DataMixin, ContextInstanceMixin): A thumbnail‘s width and height should not exceed 320. :type thumbnail: :obj:`typing.Union[typing.Union[base.InputFile, base.String], None]` - :param thumb: Thumbnail of the file sent. The thumbnail should be in JPEG format and less than 200 kB in size. - A thumbnail‘s width and height should not exceed 320. + :param thumb: deprecated in API 6.6. Use thumbnail instead :type thumb: :obj:`typing.Union[typing.Union[base.InputFile, base.String], None]` :param caption: Animation caption (may also be used when resending animation by file_id), 0-1024 characters @@ -1074,6 +1086,7 @@ class Bot(BaseBot, DataMixin, ContextInstanceMixin): result = await self.request(api.Methods.SEND_VOICE, payload, files) return types.Message(**result) + @renamed_argument('thumb', 'thumbnail', '3.0') async def send_video_note(self, chat_id: typing.Union[base.Integer, base.String], video_note: typing.Union[base.InputFile, base.String], duration: typing.Optional[base.Integer] = None, @@ -1115,7 +1128,7 @@ class Bot(BaseBot, DataMixin, ContextInstanceMixin): :param thumbnail: Thumbnail of the file sent :type thumbnail: :obj:`typing.Union[base.InputFile, base.String, None]` - :param thumb: Thumbnail of the file sent + :param thumb: deprecated in API 6.6. Use thumbnail instead :type thumb: :obj:`typing.Union[base.InputFile, base.String, None]` :param disable_notification: Sends the message silently. Users will receive a notification with no sound From 64f139a43d7ef947dbde48fe45d63468480c01dd Mon Sep 17 00:00:00 2001 From: latan Date: Wed, 22 Mar 2023 15:08:46 +0200 Subject: [PATCH 3/5] Remove duplicate deprecated warn --- aiogram/bot/bot.py | 9 --------- 1 file changed, 9 deletions(-) diff --git a/aiogram/bot/bot.py b/aiogram/bot/bot.py index ccc342d1..7a54d5ba 100644 --- a/aiogram/bot/bot.py +++ b/aiogram/bot/bot.py @@ -661,15 +661,6 @@ class Bot(BaseBot, DataMixin, ContextInstanceMixin): payload.setdefault('parse_mode', self.parse_mode) if self.protect_content is not None: payload.setdefault('protect_content', self.protect_content) - deprecated_list = [thumb] - for param in deprecated_list: - if param is None: - warnings.warn( - message=f"The parameter `{param}` deprecated, use updated method params instead.", - category=DeprecationWarning, - stacklevel=2 - ) - files = {} prepare_file(payload, files, 'audio', audio) From f70c97e9fa0cc9469dc683b7db44823c95dc979e Mon Sep 17 00:00:00 2001 From: latan Date: Wed, 22 Mar 2023 18:14:27 +0200 Subject: [PATCH 4/5] - Renamed the field thumb in the classes Animation, Audio, Document, Sticker, Video, VideoNote, InputMediaAnimation, InputMediaAudio, InputMediaDocument, InputMediaVideo, StickerSet to thumbnail. - Renamed the fields thumb_url, thumb_width, and thumb_height in the classes InlineQueryResultArticle, InlineQueryResultContact, InlineQueryResultDocument, InlineQueryResultLocation, and InlineQueryResultVenue to thumbnail_url, thumbnail_width, and thumbnail_height respectively. - Renamed the field thumb_url in the classes InlineQueryResultPhoto and InlineQueryResultVideo to thumbnail_url. - Renamed the fields thumb_url and thumb_mime_type in the classes InlineQueryResultGif, and InlineQueryResultMpeg4Gif to thumbnail_url and thumbnail_mime_type respectively. --- aiogram/types/animation.py | 37 +++- aiogram/types/audio.py | 37 +++- aiogram/types/document.py | 31 ++- aiogram/types/inline_query_result.py | 276 +++++++++++++++++++++++---- aiogram/types/input_media.py | 48 ++++- aiogram/types/sticker.py | 47 +++++ aiogram/types/sticker_set.py | 33 +++- aiogram/types/video.py | 37 +++- aiogram/types/video_note.py | 31 ++- 9 files changed, 521 insertions(+), 56 deletions(-) diff --git a/aiogram/types/animation.py b/aiogram/types/animation.py index b08089c1..21e8c995 100644 --- a/aiogram/types/animation.py +++ b/aiogram/types/animation.py @@ -1,7 +1,10 @@ +import typing + from . import base from . import fields from . import mixins from .photo_size import PhotoSize +from ..utils.deprecated import warn_deprecated class Animation(base.TelegramObject, mixins.Downloadable): @@ -18,7 +21,39 @@ class Animation(base.TelegramObject, mixins.Downloadable): width: base.Integer = fields.Field() height: base.Integer = fields.Field() duration: base.Integer = fields.Field() - thumb: PhotoSize = fields.Field(base=PhotoSize) + thumb: PhotoSize = fields.Field(base=PhotoSize) # Deprecated + thumbnail: PhotoSize = fields.Field(base=PhotoSize) file_name: base.String = fields.Field() mime_type: base.String = fields.Field() file_size: base.Integer = fields.Field() + + def __init__( + self, + file_id: base.String, + file_unique_id: base.String, + width: base.Integer, + height: base.Integer, + duration: base.Integer, + thumb: typing.Optional[PhotoSize] = None, + thumbnail: typing.Optional[PhotoSize] = None, + file_name: typing.Optional[base.String] = None, + mime_type: typing.Optional[base.String] = None, + file_size: typing.Optional[base.Integer] = None, + ): + if not thumbnail and thumb: + thumbnail = thumb + warn_deprecated( + "thumb is deprecated. Use thumbnail instead", + ) + + super().__init__( + file_id=file_id, + file_unique_id=file_unique_id, + width=width, + height=height, + duration=duration, + thumbnail=thumbnail, + file_name=file_name, + mime_type=mime_type, + file_size=file_size, + ) diff --git a/aiogram/types/audio.py b/aiogram/types/audio.py index 1657c9cc..36599dc2 100644 --- a/aiogram/types/audio.py +++ b/aiogram/types/audio.py @@ -1,7 +1,10 @@ +import typing + from . import base from . import fields from . import mixins from .photo_size import PhotoSize +from ..utils.deprecated import warn_deprecated class Audio(base.TelegramObject, mixins.Downloadable): @@ -18,4 +21,36 @@ class Audio(base.TelegramObject, mixins.Downloadable): file_name: base.String = fields.Field() mime_type: base.String = fields.Field() file_size: base.Integer = fields.Field() - thumb: PhotoSize = fields.Field(base=PhotoSize) + thumb: PhotoSize = fields.Field(base=PhotoSize) # Deprecated + thumbnail: PhotoSize = fields.Field(base=PhotoSize) + + def __init__( + self, + file_id: base.String, + file_unique_id: base.String, + duration: base.Integer, + performer: typing.Optional[base.String] = None, + title: typing.Optional[base.String] = None, + file_name: typing.Optional[base.String] = None, + mime_type: typing.Optional[base.String] = None, + file_size: typing.Optional[base.Integer] = None, + thumb: typing.Optional[PhotoSize] = None, + thumbnail: typing.Optional[PhotoSize] = None, + ): + if not thumbnail and thumb: + thumbnail = thumb + warn_deprecated( + "thumb is deprecated. Use thumbnail instead", + ) + + super().__init__( + file_id=file_id, + file_unique_id=file_unique_id, + duration=duration, + performer=performer, + title=title, + file_name=file_name, + mime_type=mime_type, + file_size=file_size, + thumbnail=thumbnail, + ) diff --git a/aiogram/types/document.py b/aiogram/types/document.py index c3d19fa9..10adb657 100644 --- a/aiogram/types/document.py +++ b/aiogram/types/document.py @@ -1,8 +1,11 @@ +import typing + from . import base from . import fields from . import mixins from .photo_size import PhotoSize from ..utils import helper +from ..utils.deprecated import warn_deprecated class Document(base.TelegramObject, mixins.Downloadable): @@ -13,11 +16,37 @@ class Document(base.TelegramObject, mixins.Downloadable): """ file_id: base.String = fields.Field() file_unique_id: base.String = fields.Field() - thumb: PhotoSize = fields.Field(base=PhotoSize) + thumb: PhotoSize = fields.Field(base=PhotoSize) # Deprecated + thumbnail: PhotoSize = fields.Field(base=PhotoSize) file_name: base.String = fields.Field() mime_type: base.String = fields.Field() file_size: base.Integer = fields.Field() + def __init__( + self, + file_id: base.String, + file_unique_id: base.String, + thumb: typing.Optional[PhotoSize] = None, + thumbnail: typing.Optional[PhotoSize] = None, + file_name: typing.Optional[base.String] = None, + mime_type: typing.Optional[base.String] = None, + file_size: typing.Optional[base.Integer] = None, + ): + if not thumbnail and thumb: + thumbnail = thumb + warn_deprecated( + "thumb is deprecated. Use thumbnail instead", + ) + + super().__init__( + file_id=file_id, + file_unique_id=file_unique_id, + thumbnail=thumbnail, + file_name=file_name, + mime_type=mime_type, + file_size=file_size, + ) + @property def mime_base(self) -> str: base_type, _, _ = self.mime_type.partition('/') diff --git a/aiogram/types/inline_query_result.py b/aiogram/types/inline_query_result.py index da09db9d..14ceb8bc 100644 --- a/aiogram/types/inline_query_result.py +++ b/aiogram/types/inline_query_result.py @@ -5,6 +5,7 @@ from . import fields from .inline_keyboard import InlineKeyboardMarkup from .input_message_content import InputMessageContent from .message_entity import MessageEntity +from ..utils.deprecated import warn_deprecated class InlineQueryResult(base.TelegramObject): @@ -42,9 +43,14 @@ class InlineQueryResultArticle(InlineQueryResult): url: base.String = fields.Field() hide_url: base.Boolean = fields.Field() description: base.String = fields.Field() - thumb_url: base.String = fields.Field() - thumb_width: base.Integer = fields.Field() - thumb_height: base.Integer = fields.Field() + # Deprecated fields + thumb_url: base.String = fields.Field() # Deprecated, use thumbnail_url instead + thumb_width: base.Integer = fields.Field() # Deprecated, use thumbnail_width instead + thumb_height: base.Integer = fields.Field() # Deprecated, use thumbnail_height instead + # New fields + thumbnail_url: base.String = fields.Field() + thumbnail_width: base.Integer = fields.Field() + thumbnail_height: base.Integer = fields.Field() def __init__(self, *, id: base.String, @@ -54,14 +60,37 @@ class InlineQueryResultArticle(InlineQueryResult): url: typing.Optional[base.String] = None, hide_url: typing.Optional[base.Boolean] = None, description: typing.Optional[base.String] = None, - thumb_url: typing.Optional[base.String] = None, - thumb_width: typing.Optional[base.Integer] = None, - thumb_height: typing.Optional[base.Integer] = None): - super(InlineQueryResultArticle, self).__init__(id=id, title=title, - input_message_content=input_message_content, - reply_markup=reply_markup, url=url, hide_url=hide_url, - description=description, thumb_url=thumb_url, - thumb_width=thumb_width, thumb_height=thumb_height) + thumb_url: typing.Optional[base.String] = None, # Deprecated + thumb_width: typing.Optional[base.Integer] = None, # Deprecated + thumb_height: typing.Optional[base.Integer] = None, # Deprecated + thumbnail_url: typing.Optional[base.String] = None, + thumbnail_width: typing.Optional[base.Integer] = None, + thumbnail_height: typing.Optional[base.Integer] = None): + + if thumb_url and not thumbnail_url: + thumbnail_url = thumb_url + warn_deprecated( + "thumb_url parameter is deprecated, please use thumbnail_url." + ) + if thumb_width and not thumbnail_width: + thumbnail_width = thumb_width + warn_deprecated( + "thumb_width parameter is deprecated, please use thumbnail_width." + ) + if thumb_height and not thumbnail_height: + warn_deprecated( + "thumb_height parameter is deprecated, please use thumbnail_height." + ) + thumbnail_height = thumb_height + + super().__init__(id=id, title=title, + input_message_content=input_message_content, + reply_markup=reply_markup, url=url, hide_url=hide_url, + description=description, thumb_url=thumb_url, + thumb_width=thumb_width, thumb_height=thumb_height, + thumbnail_url=thumbnail_url, + thumbnail_width=thumbnail_width, + thumbnail_height=thumbnail_height) class InlineQueryResultPhoto(InlineQueryResult): @@ -76,7 +105,10 @@ class InlineQueryResultPhoto(InlineQueryResult): """ type: base.String = fields.Field(alias='type', default='photo') photo_url: base.String = fields.Field() + # Deprecated field thumb_url: base.String = fields.Field() + # New field + thumbnail_url: base.String = fields.Field() photo_width: base.Integer = fields.Field() photo_height: base.Integer = fields.Field() title: base.String = fields.Field() @@ -89,7 +121,8 @@ class InlineQueryResultPhoto(InlineQueryResult): *, id: base.String, photo_url: base.String, - thumb_url: base.String, + thumb_url: typing.Optional[base.String] = None, # Deprecated + thumbnail_url: typing.Optional[base.String] = None, photo_width: typing.Optional[base.Integer] = None, photo_height: typing.Optional[base.Integer] = None, title: typing.Optional[base.String] = None, @@ -100,8 +133,17 @@ class InlineQueryResultPhoto(InlineQueryResult): reply_markup: typing.Optional[InlineKeyboardMarkup] = None, input_message_content: typing.Optional[InputMessageContent] = None, ): + if not thumbnail_url: + if thumb_url: + warn_deprecated( + "thumb_url parameter is deprecated, please use thumbnail_url." + ) + thumbnail_url = thumb_url + else: + raise ValueError("thumbnail_url argument is required") + super().__init__( - id=id, photo_url=photo_url, thumb_url=thumb_url, + id=id, photo_url=photo_url, thumbnail_url=thumbnail_url, photo_width=photo_width, photo_height=photo_height, title=title, description=description, caption=caption, parse_mode=parse_mode, caption_entities=caption_entities, @@ -124,8 +166,12 @@ class InlineQueryResultGif(InlineQueryResult): gif_width: base.Integer = fields.Field() gif_height: base.Integer = fields.Field() gif_duration: base.Integer = fields.Field() + # Deprecated fields thumb_url: base.String = fields.Field() thumb_mime_type: base.String = fields.Field() + # New fields + thumbnail_url: base.String = fields.Field() + thumbnail_mime_type: base.String = fields.Field() title: base.String = fields.Field() caption: base.String = fields.Field() input_message_content: InputMessageContent = fields.Field(base=InputMessageContent) @@ -138,7 +184,10 @@ class InlineQueryResultGif(InlineQueryResult): gif_width: typing.Optional[base.Integer] = None, gif_height: typing.Optional[base.Integer] = None, gif_duration: typing.Optional[base.Integer] = None, - thumb_url: typing.Optional[base.String] = None, + thumb_url: typing.Optional[base.String] = None, # Deprecated + thumb_mime_type: typing.Optional[base.String] = None, # Deprecated + thumbnail_url: typing.Optional[base.String] = None, + thumbnail_mime_type: typing.Optional[base.String] = None, title: typing.Optional[base.String] = None, caption: typing.Optional[base.String] = None, parse_mode: typing.Optional[base.String] = None, @@ -146,9 +195,22 @@ class InlineQueryResultGif(InlineQueryResult): caption_entities: typing.Optional[typing.List[MessageEntity]] = None, input_message_content: typing.Optional[InputMessageContent] = None, ): + if not thumbnail_url and thumb_url: + warn_deprecated( + "thumb_url parameter is deprecated, please use thumbnail_url." + ) + thumbnail_url = thumb_url + if not thumbnail_mime_type and thumb_mime_type: + warn_deprecated( + "thumb_mime_type parameter is deprecated, please use thumbnail_mime_type." + ) + thumbnail_mime_type = thumb_mime_type + super().__init__( id=id, gif_url=gif_url, gif_width=gif_width, gif_height=gif_height, - gif_duration=gif_duration, thumb_url=thumb_url, title=title, + gif_duration=gif_duration, + thumbnail_url=thumbnail_url, thumbnail_mime_type=thumbnail_mime_type, + title=title, caption=caption, parse_mode=parse_mode, reply_markup=reply_markup, caption_entities=caption_entities, input_message_content=input_message_content, @@ -170,8 +232,12 @@ class InlineQueryResultMpeg4Gif(InlineQueryResult): mpeg4_width: base.Integer = fields.Field() mpeg4_height: base.Integer = fields.Field() mpeg4_duration: base.Integer = fields.Field() + # Deprecated fields thumb_url: base.String = fields.Field() thumb_mime_type: base.String = fields.Field() + # New fields + thumbnail_url: base.String = fields.Field() + thumbnail_mime_type: base.String = fields.Field() title: base.String = fields.Field() caption: base.String = fields.Field() input_message_content: InputMessageContent = fields.Field(base=InputMessageContent) @@ -181,7 +247,10 @@ class InlineQueryResultMpeg4Gif(InlineQueryResult): *, id: base.String, mpeg4_url: base.String, - thumb_url: base.String, + thumb_url: typing.Optional[base.String] = None, # Deprecated + thumb_mime_type: typing.Optional[base.String] = None, # Deprecated + thumbnail_url: typing.Optional[base.String] = None, + thumbnail_mime_type: typing.Optional[base.String] = None, mpeg4_width: typing.Optional[base.Integer] = None, mpeg4_height: typing.Optional[base.Integer] = None, mpeg4_duration: typing.Optional[base.Integer] = None, @@ -192,10 +261,26 @@ class InlineQueryResultMpeg4Gif(InlineQueryResult): caption_entities: typing.Optional[typing.List[MessageEntity]] = None, input_message_content: typing.Optional[InputMessageContent] = None, ): + if not thumbnail_url: + if thumb_url: + warn_deprecated( + "thumb_url parameter is deprecated, please use thumbnail_url." + ) + thumbnail_url = thumb_url + else: + raise ValueError("thumbnail_url is required") + if not thumbnail_mime_type and thumb_mime_type: + warn_deprecated( + "thumb_mime_type parameter is deprecated, please use thumbnail_mime_type." + ) + thumbnail_mime_type = thumb_mime_type + + super().__init__( id=id, mpeg4_url=mpeg4_url, mpeg4_width=mpeg4_width, mpeg4_height=mpeg4_height, mpeg4_duration=mpeg4_duration, - thumb_url=thumb_url, title=title, caption=caption, + thumbnail_url=thumbnail_url, thumbnail_mime_type=thumbnail_mime_type, + title=title, caption=caption, parse_mode=parse_mode, reply_markup=reply_markup, caption_entities=caption_entities, input_message_content=input_message_content, @@ -218,7 +303,10 @@ class InlineQueryResultVideo(InlineQueryResult): type: base.String = fields.Field(alias='type', default='video') video_url: base.String = fields.Field() mime_type: base.String = fields.Field() + # Deprecated fields thumb_url: base.String = fields.Field() + # New fields + thumbnail_url: base.String = fields.Field() title: base.String = fields.Field() caption: base.String = fields.Field() video_width: base.Integer = fields.Field() @@ -233,7 +321,8 @@ class InlineQueryResultVideo(InlineQueryResult): id: base.String, video_url: base.String, mime_type: base.String, - thumb_url: base.String, + thumb_url: typing.Optional[base.String] = None, # Deprecated + thumbnail_url: typing.Optional[base.String] = None, title: base.String, caption: typing.Optional[base.String] = None, parse_mode: typing.Optional[base.String] = None, @@ -245,8 +334,17 @@ class InlineQueryResultVideo(InlineQueryResult): caption_entities: typing.Optional[typing.List[MessageEntity]] = None, input_message_content: typing.Optional[InputMessageContent] = None, ): + if not thumbnail_url: + if thumb_url: + warn_deprecated( + "thumb_url parameter is deprecated, please use thumbnail_url." + ) + thumbnail_url = thumb_url + else: + raise ValueError("thumbnail_url is required") + super().__init__( - id=id, video_url=video_url, mime_type=mime_type, thumb_url=thumb_url, + id=id, video_url=video_url, mime_type=mime_type, thumbnail_url=thumbnail_url, title=title, caption=caption, video_width=video_width, video_height=video_height, video_duration=video_duration, description=description, parse_mode=parse_mode, @@ -357,9 +455,14 @@ class InlineQueryResultDocument(InlineQueryResult): mime_type: base.String = fields.Field() description: base.String = fields.Field() input_message_content: InputMessageContent = fields.Field(base=InputMessageContent) + # Deprecated fields thumb_url: base.String = fields.Field() thumb_width: base.Integer = fields.Field() thumb_height: base.Integer = fields.Field() + # New fields + thumbnail_url: base.String = fields.Field() + thumbnail_width: base.Integer = fields.Field() + thumbnail_height: base.Integer = fields.Field() def __init__( self, @@ -374,17 +477,36 @@ class InlineQueryResultDocument(InlineQueryResult): description: typing.Optional[base.String] = None, reply_markup: typing.Optional[InlineKeyboardMarkup] = None, input_message_content: typing.Optional[InputMessageContent] = None, - thumb_url: typing.Optional[base.String] = None, - thumb_width: typing.Optional[base.Integer] = None, - thumb_height: typing.Optional[base.Integer] = None, + thumb_url: typing.Optional[base.String] = None, # Deprecated + thumb_width: typing.Optional[base.Integer] = None, # Deprecated + thumb_height: typing.Optional[base.Integer] = None, # Deprecated + thumbnail_url: typing.Optional[base.String] = None, + thumbnail_width: typing.Optional[base.Integer] = None, + thumbnail_height: typing.Optional[base.Integer] = None, ): + if thumb_url and not thumbnail_url: + thumbnail_url = thumb_url + warn_deprecated( + 'thumb_url is deprecated, use thumbnail_url instead', + ) + if thumb_width and not thumbnail_width: + thumbnail_width = thumb_width + warn_deprecated( + 'thumb_width is deprecated, use thumbnail_width instead', + ) + if thumb_height and not thumbnail_height: + thumbnail_height = thumb_height + warn_deprecated( + 'thumb_height is deprecated, use thumbnail_height instead', + ) + super().__init__( id=id, title=title, caption=caption, parse_mode=parse_mode, caption_entities=caption_entities, document_url=document_url, mime_type=mime_type, description=description, reply_markup=reply_markup, input_message_content=input_message_content, - thumb_url=thumb_url, thumb_width=thumb_width, - thumb_height=thumb_height, + thumbnail_url=thumbnail_url, thumbnail_width=thumbnail_width, + thumbnail_height=thumbnail_height, ) @@ -407,9 +529,14 @@ class InlineQueryResultLocation(InlineQueryResult): heading: typing.Optional[base.Integer] = fields.Field() proximity_alert_radius: typing.Optional[base.Integer] = fields.Field() input_message_content: InputMessageContent = fields.Field(base=InputMessageContent) + # Deprecated fields thumb_url: base.String = fields.Field() thumb_width: base.Integer = fields.Field() thumb_height: base.Integer = fields.Field() + # New fields + thumbnail_url: base.String = fields.Field() + thumbnail_width: base.Integer = fields.Field() + thumbnail_height: base.Integer = fields.Field() def __init__(self, *, id: base.String, @@ -422,10 +549,29 @@ class InlineQueryResultLocation(InlineQueryResult): proximity_alert_radius: typing.Optional[base.Integer] = None, reply_markup: typing.Optional[InlineKeyboardMarkup] = None, input_message_content: typing.Optional[InputMessageContent] = None, - thumb_url: typing.Optional[base.String] = None, - thumb_width: typing.Optional[base.Integer] = None, - thumb_height: typing.Optional[base.Integer] = None, + thumb_url: typing.Optional[base.String] = None, # Deprecated + thumb_width: typing.Optional[base.Integer] = None, # Deprecated + thumb_height: typing.Optional[base.Integer] = None, # Deprecated + thumbnail_url: typing.Optional[base.String] = None, + thumbnail_width: typing.Optional[base.Integer] = None, + thumbnail_height: typing.Optional[base.Integer] = None, ): + if thumb_url and not thumbnail_url: + thumbnail_url = thumb_url + warn_deprecated( + 'thumb_url is deprecated, use thumbnail_url instead', + ) + if thumb_width and not thumbnail_width: + thumbnail_width = thumb_width + warn_deprecated( + 'thumb_width is deprecated, use thumbnail_width instead', + ) + if thumb_height and not thumbnail_height: + thumbnail_height = thumb_height + warn_deprecated( + 'thumb_height is deprecated, use thumbnail_height instead', + ) + super().__init__( id=id, latitude=latitude, @@ -437,9 +583,9 @@ class InlineQueryResultLocation(InlineQueryResult): proximity_alert_radius=proximity_alert_radius, reply_markup=reply_markup, input_message_content=input_message_content, - thumb_url=thumb_url, - thumb_width=thumb_width, - thumb_height=thumb_height + thumbnail_url=thumbnail_url, + thumbnail_width=thumbnail_width, + thumbnail_height=thumbnail_height, ) @@ -465,9 +611,14 @@ class InlineQueryResultVenue(InlineQueryResult): google_place_id: base.String = fields.Field() google_place_type: base.String = fields.Field() input_message_content: InputMessageContent = fields.Field(base=InputMessageContent) + # Deprecated fields thumb_url: base.String = fields.Field() thumb_width: base.Integer = fields.Field() thumb_height: base.Integer = fields.Field() + # New fields + thumbnail_url: base.String = fields.Field() + thumbnail_width: base.Integer = fields.Field() + thumbnail_height: base.Integer = fields.Field() def __init__( self, @@ -483,17 +634,36 @@ class InlineQueryResultVenue(InlineQueryResult): google_place_type: typing.Optional[base.String] = None, reply_markup: typing.Optional[InlineKeyboardMarkup] = None, input_message_content: typing.Optional[InputMessageContent] = None, - thumb_url: typing.Optional[base.String] = None, - thumb_width: typing.Optional[base.Integer] = None, - thumb_height: typing.Optional[base.Integer] = None, + thumb_url: typing.Optional[base.String] = None, # Deprecated + thumb_width: typing.Optional[base.Integer] = None, # Deprecated + thumb_height: typing.Optional[base.Integer] = None, # Deprecated + thumbnail_url: typing.Optional[base.String] = None, + thumbnail_width: typing.Optional[base.Integer] = None, + thumbnail_height: typing.Optional[base.Integer] = None, ): + if thumb_url and not thumbnail_url: + thumbnail_url = thumb_url + warn_deprecated( + 'thumb_url is deprecated, use thumbnail_url instead', + ) + if thumb_width and not thumbnail_width: + thumbnail_width = thumb_width + warn_deprecated( + 'thumb_width is deprecated, use thumbnail_width instead', + ) + if thumb_height and not thumbnail_height: + thumbnail_height = thumb_height + warn_deprecated( + 'thumb_height is deprecated, use thumbnail_height instead', + ) + super().__init__( id=id, latitude=latitude, longitude=longitude, title=title, address=address, foursquare_id=foursquare_id, foursquare_type=foursquare_type, google_place_id=google_place_id, google_place_type=google_place_type, reply_markup=reply_markup, - input_message_content=input_message_content, thumb_url=thumb_url, - thumb_width=thumb_width, thumb_height=thumb_height, + input_message_content=input_message_content, thumbnail_url=thumbnail_url, + thumbnail_width=thumbnail_width, thumbnail_height=thumbnail_height, ) @@ -515,9 +685,14 @@ class InlineQueryResultContact(InlineQueryResult): last_name: base.String = fields.Field() vcard: base.String = fields.Field() input_message_content: InputMessageContent = fields.Field(base=InputMessageContent) + # Deprecated fields thumb_url: base.String = fields.Field() thumb_width: base.Integer = fields.Field() thumb_height: base.Integer = fields.Field() + # New fields + thumbnail_url: base.String = fields.Field() + thumbnail_width: base.Integer = fields.Field() + thumbnail_height: base.Integer = fields.Field() foursquare_type: base.String = fields.Field() def __init__(self, *, @@ -527,15 +702,36 @@ class InlineQueryResultContact(InlineQueryResult): last_name: typing.Optional[base.String] = None, reply_markup: typing.Optional[InlineKeyboardMarkup] = None, input_message_content: typing.Optional[InputMessageContent] = None, - thumb_url: typing.Optional[base.String] = None, - thumb_width: typing.Optional[base.Integer] = None, - thumb_height: typing.Optional[base.Integer] = None, + thumb_url: typing.Optional[base.String] = None, # Deprecated + thumb_width: typing.Optional[base.Integer] = None, # Deprecated + thumb_height: typing.Optional[base.Integer] = None, # Deprecated + thumbnail_url: typing.Optional[base.String] = None, + thumbnail_width: typing.Optional[base.Integer] = None, + thumbnail_height: typing.Optional[base.Integer] = None, foursquare_type: typing.Optional[base.String] = None): + if thumb_url and not thumbnail_url: + thumbnail_url = thumb_url + warn_deprecated( + 'thumb_url is deprecated, use thumbnail_url instead', + ) + if thumb_width and not thumbnail_width: + thumbnail_width = thumb_width + warn_deprecated( + 'thumb_width is deprecated, use thumbnail_width instead', + ) + if thumb_height and not thumbnail_height: + thumbnail_height = thumb_height + warn_deprecated( + 'thumb_height is deprecated, use thumbnail_height instead', + ) + super(InlineQueryResultContact, self).__init__(id=id, phone_number=phone_number, first_name=first_name, last_name=last_name, reply_markup=reply_markup, - input_message_content=input_message_content, thumb_url=thumb_url, - thumb_width=thumb_width, thumb_height=thumb_height, + input_message_content=input_message_content, + thumbnail_url=thumbnail_url, + thumbnail_width=thumbnail_width, + thumbnail_height=thumbnail_height, foursquare_type=foursquare_type) diff --git a/aiogram/types/input_media.py b/aiogram/types/input_media.py index 876a8f41..decd4714 100644 --- a/aiogram/types/input_media.py +++ b/aiogram/types/input_media.py @@ -6,6 +6,7 @@ from . import base from . import fields from .input_file import InputFile from .message_entity import MessageEntity +from ..utils.deprecated import warn_deprecated ATTACHMENT_PREFIX = 'attach://' @@ -112,7 +113,8 @@ class InputMediaAnimation(InputMedia): def __init__( self, media: base.InputFile, - thumb: typing.Union[base.InputFile, base.String] = None, + thumb: typing.Union[base.InputFile, base.String] = None, # Deprecated + thumbnail: typing.Union[base.InputFile, base.String] = None, caption: base.String = None, width: base.Integer = None, height: base.Integer = None, @@ -122,8 +124,14 @@ class InputMediaAnimation(InputMedia): has_spoiler: typing.Optional[base.Boolean] = None, **kwargs, ): + if not thumbnail and thumb: + thumbnail = thumb + warn_deprecated( + 'thumb argument is deprecated, use thumbnail instead', + ) + super().__init__( - type='animation', media=media, thumb=thumb, caption=caption, width=width, + type='animation', media=media, thumbnail=thumbnail, caption=caption, width=width, height=height, duration=duration, parse_mode=parse_mode, caption_entities=caption_entities, has_spoiler=has_spoiler, conf=kwargs, ) @@ -139,15 +147,21 @@ class InputMediaDocument(InputMedia): def __init__( self, media: base.InputFile, - thumb: typing.Union[base.InputFile, base.String, None] = None, + thumb: typing.Union[base.InputFile, base.String, None] = None, # Deprecated + thumbnail: typing.Union[base.InputFile, base.String, None] = None, caption: base.String = None, parse_mode: base.String = None, caption_entities: typing.Optional[typing.List[MessageEntity]] = None, disable_content_type_detection: typing.Optional[base.Boolean] = None, **kwargs, ): + if not thumbnail and thumb: + thumbnail = thumb + warn_deprecated( + 'thumb argument is deprecated, use thumbnail instead', + ) super().__init__( - type='document', media=media, thumb=thumb, caption=caption, + type='document', media=media, thumbnail=thumbnail, caption=caption, parse_mode=parse_mode, caption_entities=caption_entities, disable_content_type_detection=disable_content_type_detection, conf=kwargs, @@ -168,7 +182,8 @@ class InputMediaAudio(InputMedia): def __init__( self, media: base.InputFile, - thumb: typing.Union[base.InputFile, base.String] = None, + thumb: typing.Union[base.InputFile, base.String] = None, # Deprecated + thumbnail: typing.Union[base.InputFile, base.String] = None, caption: base.String = None, duration: base.Integer = None, performer: base.String = None, @@ -177,8 +192,13 @@ class InputMediaAudio(InputMedia): caption_entities: typing.Optional[typing.List[MessageEntity]] = None, **kwargs, ): + if not thumbnail and thumb: + thumbnail = thumb + warn_deprecated( + 'thumb argument is deprecated, use thumbnail instead', + ) super().__init__( - type='audio', media=media, thumb=thumb, caption=caption, + type='audio', media=media, thumbnail=thumbnail, caption=caption, duration=duration, performer=performer, title=title, parse_mode=parse_mode, caption_entities=caption_entities, conf=kwargs, ) @@ -216,6 +236,8 @@ class InputMediaVideo(InputMedia): width: base.Integer = fields.Field() height: base.Integer = fields.Field() duration: base.Integer = fields.Field() + thumb: typing.Union[base.InputFile, base.String] = fields.Field() # Deprecated + thumbnail: typing.Union[base.InputFile, base.String] = fields.Field() supports_streaming: base.Boolean = fields.Field() has_spoiler: typing.Optional[base.Boolean] = fields.Field() @@ -223,6 +245,7 @@ class InputMediaVideo(InputMedia): self, media: base.InputFile, thumb: typing.Union[base.InputFile, base.String] = None, + thumbnail: typing.Union[base.InputFile, base.String] = None, caption: base.String = None, width: base.Integer = None, height: base.Integer = None, @@ -233,8 +256,13 @@ class InputMediaVideo(InputMedia): has_spoiler: typing.Optional[base.Boolean] = None, **kwargs, ): + if not thumbnail and thumb: + thumbnail = thumb + warn_deprecated( + 'thumb argument is deprecated, use thumbnail instead', + ) super().__init__( - type='video', media=media, thumb=thumb, caption=caption, + type='video', media=media, thumbnail=thumbnail, caption=caption, width=width, height=height, duration=duration, parse_mode=parse_mode, caption_entities=caption_entities, supports_streaming=supports_streaming, has_spoiler=has_spoiler, conf=kwargs @@ -346,7 +374,7 @@ class MediaGroup(base.TelegramObject): caption_entities=caption_entities) self.attach(audio) - def attach_document(self, document: typing.Union[InputMediaDocument, base.InputFile], + def attach_document(self, document: typing.Union[InputMediaDocument, base.InputFile], thumb: typing.Union[base.InputFile, base.String] = None, caption: base.String = None, parse_mode: base.String = None, caption_entities: typing.Optional[typing.List[MessageEntity]] = None, @@ -362,7 +390,7 @@ class MediaGroup(base.TelegramObject): :param disable_content_type_detection: """ if not isinstance(document, InputMedia): - document = InputMediaDocument(media=document, thumb=thumb, caption=caption, + document = InputMediaDocument(media=document, thumb=thumb, caption=caption, parse_mode=parse_mode, caption_entities=caption_entities, disable_content_type_detection=disable_content_type_detection) self.attach(document) @@ -386,7 +414,7 @@ class MediaGroup(base.TelegramObject): def attach_video(self, video: typing.Union[InputMediaVideo, base.InputFile], thumb: typing.Union[base.InputFile, base.String] = None, caption: base.String = None, - width: base.Integer = None, height: base.Integer = None, + width: base.Integer = None, height: base.Integer = None, duration: base.Integer = None, parse_mode: base.String = None, caption_entities: typing.Optional[typing.List[MessageEntity]] = None, supports_streaming: base.Boolean = None): diff --git a/aiogram/types/sticker.py b/aiogram/types/sticker.py index 476a1e1e..ff2d50e4 100644 --- a/aiogram/types/sticker.py +++ b/aiogram/types/sticker.py @@ -1,9 +1,12 @@ +import typing + from . import base from . import fields from . import mixins from .mask_position import MaskPosition from .photo_size import PhotoSize from .file import File +from ..utils.deprecated import warn_deprecated class Sticker(base.TelegramObject, mixins.Downloadable): @@ -20,6 +23,7 @@ class Sticker(base.TelegramObject, mixins.Downloadable): is_animated: base.Boolean = fields.Field() is_video: base.Boolean = fields.Field() thumb: PhotoSize = fields.Field(base=PhotoSize) + thumbnail: PhotoSize = fields.Field(base=PhotoSize) emoji: base.String = fields.Field() set_name: base.String = fields.Field() premium_animation: File = fields.Field(base=File) @@ -28,6 +32,49 @@ class Sticker(base.TelegramObject, mixins.Downloadable): needs_repainting: base.Boolean = fields.Field() file_size: base.Integer = fields.Field() + def __init__( + self, + file_id: base.String, + file_unique_id: base.String, + type: base.String, + width: base.Integer, + height: base.Integer, + is_animated: base.Boolean, + is_video: base.Boolean, + thumb: typing.Optional[PhotoSize] = None, + thumbnail: typing.Optional[PhotoSize] = None, + emoji: typing.Optional[base.String] = None, + set_name: typing.Optional[base.String] = None, + premium_animation: typing.Optional[File] = None, + mask_position: typing.Optional[MaskPosition] = None, + custom_emoji_id: typing.Optional[base.String] = None, + needs_repainting: typing.Optional[base.Boolean] = None, + file_size: typing.Optional[base.Integer] = None, + ): + if thumb is not None: + warn_deprecated( + "The 'thumb' parameter is deprecated, use 'thumbnail' instead." + ) + thumbnail = thumb + + super().__init__( + file_id=file_id, + file_unique_id=file_unique_id, + type=type, + width=width, + height=height, + is_animated=is_animated, + is_video=is_video, + thumbnail=thumbnail, + emoji=emoji, + set_name=set_name, + premium_animation=premium_animation, + mask_position=mask_position, + custom_emoji_id=custom_emoji_id, + needs_repainting=needs_repainting, + file_size=file_size, + ) + async def set_position_in_set(self, position: base.Integer) -> base.Boolean: """ Use this method to move a sticker in a set created by the bot to a specific position. diff --git a/aiogram/types/sticker_set.py b/aiogram/types/sticker_set.py index 809094c2..16f31d78 100644 --- a/aiogram/types/sticker_set.py +++ b/aiogram/types/sticker_set.py @@ -4,6 +4,7 @@ from . import base from . import fields from .photo_size import PhotoSize from .sticker import Sticker +from ..utils.deprecated import warn_deprecated class StickerSet(base.TelegramObject): @@ -19,4 +20,34 @@ class StickerSet(base.TelegramObject): is_video: base.Boolean = fields.Field() contains_masks: base.Boolean = fields.Field() # Deprecated stickers: typing.List[Sticker] = fields.ListField(base=Sticker) - thumb: PhotoSize = fields.Field(base=PhotoSize) + thumb: PhotoSize = fields.Field(base=PhotoSize) # Deprecated + thumbnail: PhotoSize = fields.Field(base=PhotoSize) + + def __init__( + self, + name: base.String, + title: base.String, + sticker_type: base.String, + is_animated: base.Boolean, + is_video: base.Boolean, + contains_masks: typing.Optional[base.Boolean] = None, + stickers: typing.List[Sticker] = None, + thumb: typing.Optional[PhotoSize] = None, + thumbnail: typing.Optional[PhotoSize] = None, + ): + if not thumbnail and thumb: + thumbnail = thumb + warn_deprecated( + "thumb is deprecated. Use thumbnail instead", + ) + + super().__init__( + name=name, + title=title, + sticker_type=sticker_type, + is_animated=is_animated, + is_video=is_video, + contains_masks=contains_masks, + stickers=stickers, + thumbnail=thumbnail, + ) diff --git a/aiogram/types/video.py b/aiogram/types/video.py index d4958761..58a7b0e3 100644 --- a/aiogram/types/video.py +++ b/aiogram/types/video.py @@ -1,7 +1,10 @@ +import typing + from . import base from . import fields from . import mixins from .photo_size import PhotoSize +from ..utils.deprecated import warn_deprecated class Video(base.TelegramObject, mixins.Downloadable): @@ -15,7 +18,39 @@ class Video(base.TelegramObject, mixins.Downloadable): width: base.Integer = fields.Field() height: base.Integer = fields.Field() duration: base.Integer = fields.Field() - thumb: PhotoSize = fields.Field(base=PhotoSize) + thumb: PhotoSize = fields.Field(base=PhotoSize) # Deprecated + thumbnail: PhotoSize = fields.Field(base=PhotoSize) file_name: base.String = fields.Field() mime_type: base.String = fields.Field() file_size: base.Integer = fields.Field() + + def __init__( + self, + file_id: base.String, + file_unique_id: base.String, + width: base.Integer, + height: base.Integer, + duration: base.Integer, + thumb: typing.Optional[PhotoSize] = None, + thumbnail: typing.Optional[PhotoSize] = None, + file_name: typing.Optional[base.String] = None, + mime_type: typing.Optional[base.String] = None, + file_size: typing.Optional[base.Integer] = None, + ): + if not thumbnail and thumb: + thumbnail = thumb + warn_deprecated( + "thumb is deprecated. Use thumbnail instead", + ) + + super().__init__( + file_id=file_id, + file_unique_id=file_unique_id, + width=width, + height=height, + duration=duration, + thumbnail=thumbnail, + file_name=file_name, + mime_type=mime_type, + file_size=file_size, + ) diff --git a/aiogram/types/video_note.py b/aiogram/types/video_note.py index 8702faae..5ab7e825 100644 --- a/aiogram/types/video_note.py +++ b/aiogram/types/video_note.py @@ -1,7 +1,10 @@ +import typing + from . import base from . import fields from . import mixins from .photo_size import PhotoSize +from ..utils.deprecated import warn_deprecated class VideoNote(base.TelegramObject, mixins.Downloadable): @@ -14,5 +17,31 @@ class VideoNote(base.TelegramObject, mixins.Downloadable): file_unique_id: base.String = fields.Field() length: base.Integer = fields.Field() duration: base.Integer = fields.Field() - thumb: PhotoSize = fields.Field(base=PhotoSize) + thumb: PhotoSize = fields.Field(base=PhotoSize) # Deprecated + thumbnail: PhotoSize = fields.Field(base=PhotoSize) file_size: base.Integer = fields.Field() + + def __init__( + self, + file_id: base.String, + file_unique_id: base.String, + length: base.Integer, + duration: base.Integer, + thumb: typing.Optional[PhotoSize] = None, + thumbnail: typing.Optional[PhotoSize] = None, + file_size: typing.Optional[base.Integer] = None, + ): + if not thumbnail and thumb: + thumbnail = thumb + warn_deprecated( + "thumb is deprecated. Use thumbnail instead", + ) + + super().__init__( + file_id=file_id, + file_unique_id=file_unique_id, + length=length, + duration=duration, + thumbnail=thumbnail, + file_size=file_size, + ) From 1975232a43f6996ef721b8cd1e03df53cf17d91c Mon Sep 17 00:00:00 2001 From: latan Date: Wed, 22 Mar 2023 18:36:45 +0200 Subject: [PATCH 5/5] Remove init, add property for renamed field --- aiogram/types/animation.py | 37 ++++----------------------- aiogram/types/audio.py | 37 ++++----------------------- aiogram/types/document.py | 29 +++------------------ aiogram/types/sticker.py | 49 +++++------------------------------- aiogram/types/sticker_set.py | 33 +++--------------------- aiogram/types/video.py | 34 ++++--------------------- aiogram/types/video_note.py | 29 ++++----------------- 7 files changed, 34 insertions(+), 214 deletions(-) diff --git a/aiogram/types/animation.py b/aiogram/types/animation.py index 21e8c995..af463b0a 100644 --- a/aiogram/types/animation.py +++ b/aiogram/types/animation.py @@ -1,5 +1,3 @@ -import typing - from . import base from . import fields from . import mixins @@ -21,39 +19,14 @@ class Animation(base.TelegramObject, mixins.Downloadable): width: base.Integer = fields.Field() height: base.Integer = fields.Field() duration: base.Integer = fields.Field() - thumb: PhotoSize = fields.Field(base=PhotoSize) # Deprecated thumbnail: PhotoSize = fields.Field(base=PhotoSize) file_name: base.String = fields.Field() mime_type: base.String = fields.Field() file_size: base.Integer = fields.Field() - def __init__( - self, - file_id: base.String, - file_unique_id: base.String, - width: base.Integer, - height: base.Integer, - duration: base.Integer, - thumb: typing.Optional[PhotoSize] = None, - thumbnail: typing.Optional[PhotoSize] = None, - file_name: typing.Optional[base.String] = None, - mime_type: typing.Optional[base.String] = None, - file_size: typing.Optional[base.Integer] = None, - ): - if not thumbnail and thumb: - thumbnail = thumb - warn_deprecated( - "thumb is deprecated. Use thumbnail instead", - ) - - super().__init__( - file_id=file_id, - file_unique_id=file_unique_id, - width=width, - height=height, - duration=duration, - thumbnail=thumbnail, - file_name=file_name, - mime_type=mime_type, - file_size=file_size, + @property + def thumb(self): + warn_deprecated( + "thumb is deprecated. Use thumbnail instead", ) + return self.thumbnail diff --git a/aiogram/types/audio.py b/aiogram/types/audio.py index 36599dc2..fc997ee0 100644 --- a/aiogram/types/audio.py +++ b/aiogram/types/audio.py @@ -1,5 +1,3 @@ -import typing - from . import base from . import fields from . import mixins @@ -21,36 +19,11 @@ class Audio(base.TelegramObject, mixins.Downloadable): file_name: base.String = fields.Field() mime_type: base.String = fields.Field() file_size: base.Integer = fields.Field() - thumb: PhotoSize = fields.Field(base=PhotoSize) # Deprecated thumbnail: PhotoSize = fields.Field(base=PhotoSize) - def __init__( - self, - file_id: base.String, - file_unique_id: base.String, - duration: base.Integer, - performer: typing.Optional[base.String] = None, - title: typing.Optional[base.String] = None, - file_name: typing.Optional[base.String] = None, - mime_type: typing.Optional[base.String] = None, - file_size: typing.Optional[base.Integer] = None, - thumb: typing.Optional[PhotoSize] = None, - thumbnail: typing.Optional[PhotoSize] = None, - ): - if not thumbnail and thumb: - thumbnail = thumb - warn_deprecated( - "thumb is deprecated. Use thumbnail instead", - ) - - super().__init__( - file_id=file_id, - file_unique_id=file_unique_id, - duration=duration, - performer=performer, - title=title, - file_name=file_name, - mime_type=mime_type, - file_size=file_size, - thumbnail=thumbnail, + @property + def thumb(self): + warn_deprecated( + "thumb is deprecated. Use thumbnail instead", ) + return self.thumbnail diff --git a/aiogram/types/document.py b/aiogram/types/document.py index 10adb657..ac0e1039 100644 --- a/aiogram/types/document.py +++ b/aiogram/types/document.py @@ -16,36 +16,15 @@ class Document(base.TelegramObject, mixins.Downloadable): """ file_id: base.String = fields.Field() file_unique_id: base.String = fields.Field() - thumb: PhotoSize = fields.Field(base=PhotoSize) # Deprecated thumbnail: PhotoSize = fields.Field(base=PhotoSize) file_name: base.String = fields.Field() mime_type: base.String = fields.Field() file_size: base.Integer = fields.Field() - def __init__( - self, - file_id: base.String, - file_unique_id: base.String, - thumb: typing.Optional[PhotoSize] = None, - thumbnail: typing.Optional[PhotoSize] = None, - file_name: typing.Optional[base.String] = None, - mime_type: typing.Optional[base.String] = None, - file_size: typing.Optional[base.Integer] = None, - ): - if not thumbnail and thumb: - thumbnail = thumb - warn_deprecated( - "thumb is deprecated. Use thumbnail instead", - ) - - super().__init__( - file_id=file_id, - file_unique_id=file_unique_id, - thumbnail=thumbnail, - file_name=file_name, - mime_type=mime_type, - file_size=file_size, - ) + @property + def thumb(self): + warn_deprecated('thumb is deprecated, use thumbnail instead') + return self.thumbnail @property def mime_base(self) -> str: diff --git a/aiogram/types/sticker.py b/aiogram/types/sticker.py index ff2d50e4..1f04a80f 100644 --- a/aiogram/types/sticker.py +++ b/aiogram/types/sticker.py @@ -3,9 +3,9 @@ import typing from . import base from . import fields from . import mixins +from .file import File from .mask_position import MaskPosition from .photo_size import PhotoSize -from .file import File from ..utils.deprecated import warn_deprecated @@ -22,7 +22,6 @@ class Sticker(base.TelegramObject, mixins.Downloadable): height: base.Integer = fields.Field() is_animated: base.Boolean = fields.Field() is_video: base.Boolean = fields.Field() - thumb: PhotoSize = fields.Field(base=PhotoSize) thumbnail: PhotoSize = fields.Field(base=PhotoSize) emoji: base.String = fields.Field() set_name: base.String = fields.Field() @@ -32,48 +31,12 @@ class Sticker(base.TelegramObject, mixins.Downloadable): needs_repainting: base.Boolean = fields.Field() file_size: base.Integer = fields.Field() - def __init__( - self, - file_id: base.String, - file_unique_id: base.String, - type: base.String, - width: base.Integer, - height: base.Integer, - is_animated: base.Boolean, - is_video: base.Boolean, - thumb: typing.Optional[PhotoSize] = None, - thumbnail: typing.Optional[PhotoSize] = None, - emoji: typing.Optional[base.String] = None, - set_name: typing.Optional[base.String] = None, - premium_animation: typing.Optional[File] = None, - mask_position: typing.Optional[MaskPosition] = None, - custom_emoji_id: typing.Optional[base.String] = None, - needs_repainting: typing.Optional[base.Boolean] = None, - file_size: typing.Optional[base.Integer] = None, - ): - if thumb is not None: - warn_deprecated( - "The 'thumb' parameter is deprecated, use 'thumbnail' instead." - ) - thumbnail = thumb - - super().__init__( - file_id=file_id, - file_unique_id=file_unique_id, - type=type, - width=width, - height=height, - is_animated=is_animated, - is_video=is_video, - thumbnail=thumbnail, - emoji=emoji, - set_name=set_name, - premium_animation=premium_animation, - mask_position=mask_position, - custom_emoji_id=custom_emoji_id, - needs_repainting=needs_repainting, - file_size=file_size, + @property + def thumb(self) -> typing.Optional[PhotoSize]: + warn_deprecated( + "The 'thumb' property is deprecated, use 'thumbnail' instead." ) + return self.thumbnail async def set_position_in_set(self, position: base.Integer) -> base.Boolean: """ diff --git a/aiogram/types/sticker_set.py b/aiogram/types/sticker_set.py index 16f31d78..d9857af5 100644 --- a/aiogram/types/sticker_set.py +++ b/aiogram/types/sticker_set.py @@ -20,34 +20,9 @@ class StickerSet(base.TelegramObject): is_video: base.Boolean = fields.Field() contains_masks: base.Boolean = fields.Field() # Deprecated stickers: typing.List[Sticker] = fields.ListField(base=Sticker) - thumb: PhotoSize = fields.Field(base=PhotoSize) # Deprecated thumbnail: PhotoSize = fields.Field(base=PhotoSize) - def __init__( - self, - name: base.String, - title: base.String, - sticker_type: base.String, - is_animated: base.Boolean, - is_video: base.Boolean, - contains_masks: typing.Optional[base.Boolean] = None, - stickers: typing.List[Sticker] = None, - thumb: typing.Optional[PhotoSize] = None, - thumbnail: typing.Optional[PhotoSize] = None, - ): - if not thumbnail and thumb: - thumbnail = thumb - warn_deprecated( - "thumb is deprecated. Use thumbnail instead", - ) - - super().__init__( - name=name, - title=title, - sticker_type=sticker_type, - is_animated=is_animated, - is_video=is_video, - contains_masks=contains_masks, - stickers=stickers, - thumbnail=thumbnail, - ) + @property + def thumb(self): + warn_deprecated('thumb is deprecated, use thumbnail instead') + return self.thumbnail diff --git a/aiogram/types/video.py b/aiogram/types/video.py index 58a7b0e3..842d2738 100644 --- a/aiogram/types/video.py +++ b/aiogram/types/video.py @@ -18,39 +18,15 @@ class Video(base.TelegramObject, mixins.Downloadable): width: base.Integer = fields.Field() height: base.Integer = fields.Field() duration: base.Integer = fields.Field() - thumb: PhotoSize = fields.Field(base=PhotoSize) # Deprecated thumbnail: PhotoSize = fields.Field(base=PhotoSize) file_name: base.String = fields.Field() mime_type: base.String = fields.Field() file_size: base.Integer = fields.Field() - def __init__( - self, - file_id: base.String, - file_unique_id: base.String, - width: base.Integer, - height: base.Integer, - duration: base.Integer, - thumb: typing.Optional[PhotoSize] = None, - thumbnail: typing.Optional[PhotoSize] = None, - file_name: typing.Optional[base.String] = None, - mime_type: typing.Optional[base.String] = None, - file_size: typing.Optional[base.Integer] = None, - ): - if not thumbnail and thumb: - thumbnail = thumb - warn_deprecated( - "thumb is deprecated. Use thumbnail instead", - ) - super().__init__( - file_id=file_id, - file_unique_id=file_unique_id, - width=width, - height=height, - duration=duration, - thumbnail=thumbnail, - file_name=file_name, - mime_type=mime_type, - file_size=file_size, + @property + def thumb(self): + warn_deprecated( + "thumb is deprecated. Use thumbnail instead", ) + return self.thumbnail diff --git a/aiogram/types/video_note.py b/aiogram/types/video_note.py index 5ab7e825..f4c8640b 100644 --- a/aiogram/types/video_note.py +++ b/aiogram/types/video_note.py @@ -17,31 +17,12 @@ class VideoNote(base.TelegramObject, mixins.Downloadable): file_unique_id: base.String = fields.Field() length: base.Integer = fields.Field() duration: base.Integer = fields.Field() - thumb: PhotoSize = fields.Field(base=PhotoSize) # Deprecated thumbnail: PhotoSize = fields.Field(base=PhotoSize) file_size: base.Integer = fields.Field() - def __init__( - self, - file_id: base.String, - file_unique_id: base.String, - length: base.Integer, - duration: base.Integer, - thumb: typing.Optional[PhotoSize] = None, - thumbnail: typing.Optional[PhotoSize] = None, - file_size: typing.Optional[base.Integer] = None, - ): - if not thumbnail and thumb: - thumbnail = thumb - warn_deprecated( - "thumb is deprecated. Use thumbnail instead", - ) - - super().__init__( - file_id=file_id, - file_unique_id=file_unique_id, - length=length, - duration=duration, - thumbnail=thumbnail, - file_size=file_size, + @property + def thumb(self): + warn_deprecated( + "thumb is deprecated. Use thumbnail instead", ) + return self.thumbnail