From 1975232a43f6996ef721b8cd1e03df53cf17d91c Mon Sep 17 00:00:00 2001 From: latan Date: Wed, 22 Mar 2023 18:36:45 +0200 Subject: [PATCH] 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