From eeb3b63b97e1946e1e4f062b0ea9892c24c88ea5 Mon Sep 17 00:00:00 2001 From: Alex Root Junior Date: Sun, 26 Jan 2020 21:09:47 +0200 Subject: [PATCH] Make some objects mutable --- aiogram/api/types/base.py | 11 +++++++++-- aiogram/api/types/chat_permissions.py | 4 ++-- aiogram/api/types/force_reply.py | 4 ++-- aiogram/api/types/inline_keyboard_button.py | 4 ++-- aiogram/api/types/inline_keyboard_markup.py | 4 ++-- aiogram/api/types/inline_query_result.py | 4 ++-- aiogram/api/types/input_media.py | 4 ++-- aiogram/api/types/input_message_content.py | 4 ++-- aiogram/api/types/keyboard_button.py | 4 ++-- aiogram/api/types/keyboard_button_poll_type.py | 4 ++-- aiogram/api/types/labeled_price.py | 4 ++-- aiogram/api/types/passport_element_error.py | 4 ++-- aiogram/api/types/reply_keyboard_markup.py | 4 ++-- aiogram/api/types/reply_keyboard_remove.py | 6 +++--- 14 files changed, 36 insertions(+), 29 deletions(-) diff --git a/aiogram/api/types/base.py b/aiogram/api/types/base.py index 46351c51..057c4b3d 100644 --- a/aiogram/api/types/base.py +++ b/aiogram/api/types/base.py @@ -1,14 +1,21 @@ import datetime +from pydantic import BaseModel, Extra + from aiogram.utils.mixins import ContextInstanceMixin -from pydantic import BaseConfig, BaseModel, Extra class TelegramObject(ContextInstanceMixin, BaseModel): - class Config(BaseConfig): + class Config: use_enum_values = True orm_mode = True extra = Extra.allow validate_assignment = True + allow_mutation = False allow_population_by_field_name = True json_encoders = {datetime.datetime: lambda dt: int(dt.timestamp())} + + +class MutableTelegramObject(TelegramObject): + class Config: + allow_mutation = True diff --git a/aiogram/api/types/chat_permissions.py b/aiogram/api/types/chat_permissions.py index b75da52b..aef8d9ff 100644 --- a/aiogram/api/types/chat_permissions.py +++ b/aiogram/api/types/chat_permissions.py @@ -2,10 +2,10 @@ from __future__ import annotations from typing import Optional -from .base import TelegramObject +from .base import MutableTelegramObject -class ChatPermissions(TelegramObject): +class ChatPermissions(MutableTelegramObject): """ Describes actions that a non-administrator user is allowed to take in a chat. diff --git a/aiogram/api/types/force_reply.py b/aiogram/api/types/force_reply.py index 5652b0ae..8ef4a1bd 100644 --- a/aiogram/api/types/force_reply.py +++ b/aiogram/api/types/force_reply.py @@ -2,10 +2,10 @@ from __future__ import annotations from typing import Optional -from .base import TelegramObject +from .base import MutableTelegramObject -class ForceReply(TelegramObject): +class ForceReply(MutableTelegramObject): """ Upon receiving a message with this object, Telegram clients will display a reply interface to the user (act as if the user has selected the bot‘s message and tapped ’Reply'). This can be diff --git a/aiogram/api/types/inline_keyboard_button.py b/aiogram/api/types/inline_keyboard_button.py index 6ef9fa8b..b157c666 100644 --- a/aiogram/api/types/inline_keyboard_button.py +++ b/aiogram/api/types/inline_keyboard_button.py @@ -2,14 +2,14 @@ from __future__ import annotations from typing import TYPE_CHECKING, Optional -from .base import TelegramObject +from .base import MutableTelegramObject if TYPE_CHECKING: # pragma: no cover from .callback_game import CallbackGame from .login_url import LoginUrl -class InlineKeyboardButton(TelegramObject): +class InlineKeyboardButton(MutableTelegramObject): """ This object represents one button of an inline keyboard. You must use exactly one of the optional fields. diff --git a/aiogram/api/types/inline_keyboard_markup.py b/aiogram/api/types/inline_keyboard_markup.py index b2bd2be4..73c43f0d 100644 --- a/aiogram/api/types/inline_keyboard_markup.py +++ b/aiogram/api/types/inline_keyboard_markup.py @@ -2,13 +2,13 @@ from __future__ import annotations from typing import TYPE_CHECKING, List -from .base import TelegramObject +from .base import MutableTelegramObject if TYPE_CHECKING: # pragma: no cover from .inline_keyboard_button import InlineKeyboardButton -class InlineKeyboardMarkup(TelegramObject): +class InlineKeyboardMarkup(MutableTelegramObject): """ This object represents an inline keyboard that appears right next to the message it belongs to. diff --git a/aiogram/api/types/inline_query_result.py b/aiogram/api/types/inline_query_result.py index 95f97dac..9df3573b 100644 --- a/aiogram/api/types/inline_query_result.py +++ b/aiogram/api/types/inline_query_result.py @@ -1,9 +1,9 @@ from __future__ import annotations -from .base import TelegramObject +from .base import MutableTelegramObject -class InlineQueryResult(TelegramObject): +class InlineQueryResult(MutableTelegramObject): """ This object represents one result of an inline query. Telegram clients currently support results of the following 20 types: diff --git a/aiogram/api/types/input_media.py b/aiogram/api/types/input_media.py index 17d05096..a9e7b2be 100644 --- a/aiogram/api/types/input_media.py +++ b/aiogram/api/types/input_media.py @@ -1,9 +1,9 @@ from __future__ import annotations -from .base import TelegramObject +from .base import MutableTelegramObject -class InputMedia(TelegramObject): +class InputMedia(MutableTelegramObject): """ This object represents the content of a media message to be sent. It should be one of - InputMediaAnimation diff --git a/aiogram/api/types/input_message_content.py b/aiogram/api/types/input_message_content.py index 38da01f8..fd002b02 100644 --- a/aiogram/api/types/input_message_content.py +++ b/aiogram/api/types/input_message_content.py @@ -1,9 +1,9 @@ from __future__ import annotations -from .base import TelegramObject +from .base import MutableTelegramObject -class InputMessageContent(TelegramObject): +class InputMessageContent(MutableTelegramObject): """ This object represents the content of a message to be sent as a result of an inline query. Telegram clients currently support the following 4 types: diff --git a/aiogram/api/types/keyboard_button.py b/aiogram/api/types/keyboard_button.py index 60aebcb7..864046d5 100644 --- a/aiogram/api/types/keyboard_button.py +++ b/aiogram/api/types/keyboard_button.py @@ -2,13 +2,13 @@ from __future__ import annotations from typing import TYPE_CHECKING, Optional -from .base import TelegramObject +from .base import MutableTelegramObject if TYPE_CHECKING: # pragma: no cover from .keyboard_button_poll_type import KeyboardButtonPollType -class KeyboardButton(TelegramObject): +class KeyboardButton(MutableTelegramObject): """ This object represents one button of the reply keyboard. For simple text buttons String can be used instead of this object to specify text of the button. Optional fields request_contact, diff --git a/aiogram/api/types/keyboard_button_poll_type.py b/aiogram/api/types/keyboard_button_poll_type.py index f66ade56..fa216e45 100644 --- a/aiogram/api/types/keyboard_button_poll_type.py +++ b/aiogram/api/types/keyboard_button_poll_type.py @@ -2,10 +2,10 @@ from __future__ import annotations from typing import Optional -from .base import TelegramObject +from .base import MutableTelegramObject -class KeyboardButtonPollType(TelegramObject): +class KeyboardButtonPollType(MutableTelegramObject): """ This object represents type of a poll, which is allowed to be created and sent when the corresponding button is pressed. diff --git a/aiogram/api/types/labeled_price.py b/aiogram/api/types/labeled_price.py index 4ef21e54..1b057f38 100644 --- a/aiogram/api/types/labeled_price.py +++ b/aiogram/api/types/labeled_price.py @@ -1,9 +1,9 @@ from __future__ import annotations -from .base import TelegramObject +from .base import MutableTelegramObject -class LabeledPrice(TelegramObject): +class LabeledPrice(MutableTelegramObject): """ This object represents a portion of the price for goods or services. diff --git a/aiogram/api/types/passport_element_error.py b/aiogram/api/types/passport_element_error.py index 3dcd80a0..691cc348 100644 --- a/aiogram/api/types/passport_element_error.py +++ b/aiogram/api/types/passport_element_error.py @@ -1,9 +1,9 @@ from __future__ import annotations -from .base import TelegramObject +from .base import MutableTelegramObject -class PassportElementError(TelegramObject): +class PassportElementError(MutableTelegramObject): """ This object represents an error in the Telegram Passport element which was submitted that should be resolved by the user. It should be one of: diff --git a/aiogram/api/types/reply_keyboard_markup.py b/aiogram/api/types/reply_keyboard_markup.py index acda3c81..5d30cc9b 100644 --- a/aiogram/api/types/reply_keyboard_markup.py +++ b/aiogram/api/types/reply_keyboard_markup.py @@ -2,13 +2,13 @@ from __future__ import annotations from typing import TYPE_CHECKING, List, Optional -from .base import TelegramObject +from .base import MutableTelegramObject if TYPE_CHECKING: # pragma: no cover from .keyboard_button import KeyboardButton -class ReplyKeyboardMarkup(TelegramObject): +class ReplyKeyboardMarkup(MutableTelegramObject): """ This object represents a custom keyboard with reply options (see Introduction to bots for details and examples). diff --git a/aiogram/api/types/reply_keyboard_remove.py b/aiogram/api/types/reply_keyboard_remove.py index c31a7455..ae092d94 100644 --- a/aiogram/api/types/reply_keyboard_remove.py +++ b/aiogram/api/types/reply_keyboard_remove.py @@ -2,10 +2,10 @@ from __future__ import annotations from typing import Optional -from .base import TelegramObject +from .base import MutableTelegramObject -class ReplyKeyboardRemove(TelegramObject): +class ReplyKeyboardRemove(MutableTelegramObject): """ Upon receiving a message with this object, Telegram clients will remove the current custom keyboard and display the default letter-keyboard. By default, custom keyboards are displayed @@ -15,7 +15,7 @@ class ReplyKeyboardRemove(TelegramObject): Source: https://core.telegram.org/bots/api#replykeyboardremove """ - remove_keyboard: bool + remove_keyboard: bool = True """Requests clients to remove the custom keyboard (user will not be able to summon this keyboard; if you want to hide the keyboard from sight but keep it accessible, use one_time_keyboard in ReplyKeyboardMarkup)"""