diff --git a/aiogram/api/client/bot.py b/aiogram/api/client/bot.py index 96061c24..0d2bf1d9 100644 --- a/aiogram/api/client/bot.py +++ b/aiogram/api/client/bot.py @@ -95,6 +95,7 @@ from ..methods import ( UploadStickerFile, ) from ..types import ( + UNSET, BotCommand, Chat, ChatMember, @@ -440,7 +441,7 @@ class Bot(ContextInstanceMixin["Bot"]): self, chat_id: Union[int, str], text: str, - parse_mode: Optional[str] = None, + parse_mode: Optional[str] = UNSET, disable_web_page_preview: Optional[bool] = None, disable_notification: Optional[bool] = None, reply_to_message_id: Optional[int] = None, @@ -512,7 +513,7 @@ class Bot(ContextInstanceMixin["Bot"]): chat_id: Union[int, str], photo: Union[InputFile, str], caption: Optional[str] = None, - parse_mode: Optional[str] = None, + parse_mode: Optional[str] = UNSET, disable_notification: Optional[bool] = None, reply_to_message_id: Optional[int] = None, reply_markup: Optional[ @@ -558,7 +559,7 @@ class Bot(ContextInstanceMixin["Bot"]): chat_id: Union[int, str], audio: Union[InputFile, str], caption: Optional[str] = None, - parse_mode: Optional[str] = None, + parse_mode: Optional[str] = UNSET, duration: Optional[int] = None, performer: Optional[str] = None, title: Optional[str] = None, @@ -626,7 +627,7 @@ class Bot(ContextInstanceMixin["Bot"]): document: Union[InputFile, str], thumb: Optional[Union[InputFile, str]] = None, caption: Optional[str] = None, - parse_mode: Optional[str] = None, + parse_mode: Optional[str] = UNSET, disable_notification: Optional[bool] = None, reply_to_message_id: Optional[int] = None, reply_markup: Optional[ @@ -686,7 +687,7 @@ class Bot(ContextInstanceMixin["Bot"]): height: Optional[int] = None, thumb: Optional[Union[InputFile, str]] = None, caption: Optional[str] = None, - parse_mode: Optional[str] = None, + parse_mode: Optional[str] = UNSET, supports_streaming: Optional[bool] = None, disable_notification: Optional[bool] = None, reply_to_message_id: Optional[int] = None, @@ -755,7 +756,7 @@ class Bot(ContextInstanceMixin["Bot"]): height: Optional[int] = None, thumb: Optional[Union[InputFile, str]] = None, caption: Optional[str] = None, - parse_mode: Optional[str] = None, + parse_mode: Optional[str] = UNSET, disable_notification: Optional[bool] = None, reply_to_message_id: Optional[int] = None, reply_markup: Optional[ @@ -817,7 +818,7 @@ class Bot(ContextInstanceMixin["Bot"]): chat_id: Union[int, str], voice: Union[InputFile, str], caption: Optional[str] = None, - parse_mode: Optional[str] = None, + parse_mode: Optional[str] = UNSET, duration: Optional[int] = None, disable_notification: Optional[bool] = None, reply_to_message_id: Optional[int] = None, @@ -1819,7 +1820,7 @@ class Bot(ContextInstanceMixin["Bot"]): chat_id: Optional[Union[int, str]] = None, message_id: Optional[int] = None, inline_message_id: Optional[str] = None, - parse_mode: Optional[str] = None, + parse_mode: Optional[str] = UNSET, disable_web_page_preview: Optional[bool] = None, reply_markup: Optional[InlineKeyboardMarkup] = None, ) -> Union[Message, bool]: @@ -1861,7 +1862,7 @@ class Bot(ContextInstanceMixin["Bot"]): message_id: Optional[int] = None, inline_message_id: Optional[str] = None, caption: Optional[str] = None, - parse_mode: Optional[str] = None, + parse_mode: Optional[str] = UNSET, reply_markup: Optional[InlineKeyboardMarkup] = None, ) -> Union[Message, bool]: """ diff --git a/aiogram/api/methods/base.py b/aiogram/api/methods/base.py index 8d15edba..4fcd9ae9 100644 --- a/aiogram/api/methods/base.py +++ b/aiogram/api/methods/base.py @@ -4,10 +4,10 @@ import abc import secrets from typing import TYPE_CHECKING, Any, Dict, Generator, Generic, Optional, TypeVar, Union -from pydantic import BaseConfig, BaseModel, Extra +from pydantic import BaseConfig, BaseModel, Extra, root_validator from pydantic.generics import GenericModel -from ..types import InputFile, ResponseParameters +from ..types import UNSET, InputFile, ResponseParameters if TYPE_CHECKING: # pragma: no cover from ..client.bot import Bot @@ -46,6 +46,20 @@ class TelegramMethod(abc.ABC, BaseModel, Generic[T]): arbitrary_types_allowed = True orm_mode = True + @root_validator(pre=True) + def remove_unset(cls, values: Dict[str, Any]) -> Dict[str, Any]: + """ + Remove UNSET from `parse_mode` before fields validation. + + We use UNSET as a sentinel value for `parse_mode` and replace it to real value later. + It isn't a problem when it's just default value for a model field, but UNSET might be passing to + a model initialization from `Bot.method_name`, so we must take care of it and + remove it before fields validation. + """ + if "parse_mode" in values and values["parse_mode"] is UNSET: + values.pop("parse_mode") + return values + @property @abc.abstractmethod def __returning__(self) -> type: # pragma: no cover @@ -116,18 +130,24 @@ def prepare_media_file(data: Dict[str, Any], files: Dict[str, InputFile]) -> Non def prepare_parse_mode(root: Any, parse_mode_property: str = "parse_mode") -> None: + """ + Find and set parse_mode with highest priority. + + Developer can manually set parse_mode for each message (or message-like) object, + but if parse_mode was unset we should use value from Bot object. + + We can't use None for "unset state", because None itself is the parse_mode option. + """ if isinstance(root, list): for item in root: prepare_parse_mode(item, parse_mode_property=parse_mode_property) return - if root.get(parse_mode_property): - return + if root.get(parse_mode_property, UNSET) is UNSET: + from ..client.bot import Bot - from ..client.bot import Bot - - bot = Bot.get_current(no_error=True) - if bot and bot.parse_mode: - root[parse_mode_property] = bot.parse_mode - return - return + bot = Bot.get_current(no_error=True) + if bot and bot.parse_mode: + root[parse_mode_property] = bot.parse_mode + else: + root[parse_mode_property] = None diff --git a/aiogram/api/methods/edit_message_caption.py b/aiogram/api/methods/edit_message_caption.py index c0e14469..ebbe9c7b 100644 --- a/aiogram/api/methods/edit_message_caption.py +++ b/aiogram/api/methods/edit_message_caption.py @@ -1,6 +1,6 @@ from typing import Any, Dict, Optional, Union -from ..types import InlineKeyboardMarkup, Message +from ..types import UNSET, InlineKeyboardMarkup, Message from .base import Request, TelegramMethod, prepare_parse_mode @@ -23,8 +23,9 @@ class EditMessageCaption(TelegramMethod[Union[Message, bool]]): """Required if chat_id and message_id are not specified. Identifier of the inline message""" caption: Optional[str] = None """New caption of the message, 0-1024 characters after entities parsing""" - parse_mode: Optional[str] = None - """Mode for parsing entities in the message caption. See formatting options for more details.""" + parse_mode: Optional[str] = UNSET + """Send Markdown or HTML, if you want Telegram apps to show bold, italic, fixed-width text or + inline URLs in the media caption.""" reply_markup: Optional[InlineKeyboardMarkup] = None """A JSON-serialized object for an inline keyboard.""" diff --git a/aiogram/api/methods/edit_message_text.py b/aiogram/api/methods/edit_message_text.py index da1da00f..20098fdc 100644 --- a/aiogram/api/methods/edit_message_text.py +++ b/aiogram/api/methods/edit_message_text.py @@ -1,6 +1,6 @@ from typing import Any, Dict, Optional, Union -from ..types import InlineKeyboardMarkup, Message +from ..types import UNSET, InlineKeyboardMarkup, Message from .base import Request, TelegramMethod @@ -23,8 +23,9 @@ class EditMessageText(TelegramMethod[Union[Message, bool]]): """Required if inline_message_id is not specified. Identifier of the message to edit""" inline_message_id: Optional[str] = None """Required if chat_id and message_id are not specified. Identifier of the inline message""" - parse_mode: Optional[str] = None - """Mode for parsing entities in the message text. See formatting options for more details.""" + parse_mode: Optional[str] = UNSET + """Send Markdown or HTML, if you want Telegram apps to show bold, italic, fixed-width text or + inline URLs in your bot's message.""" disable_web_page_preview: Optional[bool] = None """Disables link previews for links in this message""" reply_markup: Optional[InlineKeyboardMarkup] = None diff --git a/aiogram/api/methods/send_animation.py b/aiogram/api/methods/send_animation.py index 6e5f6444..aca62a40 100644 --- a/aiogram/api/methods/send_animation.py +++ b/aiogram/api/methods/send_animation.py @@ -1,6 +1,7 @@ from typing import Any, Dict, Optional, Union from ..types import ( + UNSET, ForceReply, InlineKeyboardMarkup, InputFile, @@ -45,9 +46,9 @@ class SendAnimation(TelegramMethod[Message]): caption: Optional[str] = None """Animation caption (may also be used when resending animation by file_id), 0-1024 characters after entities parsing""" - parse_mode: Optional[str] = None - """Mode for parsing entities in the animation caption. See formatting options for more - details.""" + parse_mode: Optional[str] = UNSET + """Send Markdown or HTML, if you want Telegram apps to show bold, italic, fixed-width text or + inline URLs in the media caption.""" disable_notification: Optional[bool] = None """Sends the message silently. Users will receive a notification with no sound.""" reply_to_message_id: Optional[int] = None diff --git a/aiogram/api/methods/send_audio.py b/aiogram/api/methods/send_audio.py index d56782e5..be4870c4 100644 --- a/aiogram/api/methods/send_audio.py +++ b/aiogram/api/methods/send_audio.py @@ -1,6 +1,7 @@ from typing import Any, Dict, Optional, Union from ..types import ( + UNSET, ForceReply, InlineKeyboardMarkup, InputFile, @@ -33,8 +34,9 @@ class SendAudio(TelegramMethod[Message]): file from the Internet, or upload a new one using multipart/form-data.""" caption: Optional[str] = None """Audio caption, 0-1024 characters after entities parsing""" - parse_mode: Optional[str] = None - """Mode for parsing entities in the audio caption. See formatting options for more details.""" + parse_mode: Optional[str] = UNSET + """Send Markdown or HTML, if you want Telegram apps to show bold, italic, fixed-width text or + inline URLs in the media caption.""" duration: Optional[int] = None """Duration of the audio in seconds""" performer: Optional[str] = None diff --git a/aiogram/api/methods/send_document.py b/aiogram/api/methods/send_document.py index 8415aadf..c67588e4 100644 --- a/aiogram/api/methods/send_document.py +++ b/aiogram/api/methods/send_document.py @@ -1,6 +1,7 @@ from typing import Any, Dict, Optional, Union from ..types import ( + UNSET, ForceReply, InlineKeyboardMarkup, InputFile, @@ -39,8 +40,9 @@ class SendDocument(TelegramMethod[Message]): caption: Optional[str] = None """Document caption (may also be used when resending documents by file_id), 0-1024 characters after entities parsing""" - parse_mode: Optional[str] = None - """Mode for parsing entities in the document caption. See formatting options for more details.""" + parse_mode: Optional[str] = UNSET + """Send Markdown or HTML, if you want Telegram apps to show bold, italic, fixed-width text or + inline URLs in the media caption.""" disable_notification: Optional[bool] = None """Sends the message silently. Users will receive a notification with no sound.""" reply_to_message_id: Optional[int] = None diff --git a/aiogram/api/methods/send_message.py b/aiogram/api/methods/send_message.py index 080adfdb..54f0fe37 100644 --- a/aiogram/api/methods/send_message.py +++ b/aiogram/api/methods/send_message.py @@ -1,6 +1,7 @@ from typing import Any, Dict, Optional, Union from ..types import ( + UNSET, ForceReply, InlineKeyboardMarkup, Message, @@ -24,8 +25,9 @@ class SendMessage(TelegramMethod[Message]): @channelusername)""" text: str """Text of the message to be sent, 1-4096 characters after entities parsing""" - parse_mode: Optional[str] = None - """Mode for parsing entities in the message text. See formatting options for more details.""" + parse_mode: Optional[str] = UNSET + """Send Markdown or HTML, if you want Telegram apps to show bold, italic, fixed-width text or + inline URLs in your bot's message.""" disable_web_page_preview: Optional[bool] = None """Disables link previews for links in this message""" disable_notification: Optional[bool] = None diff --git a/aiogram/api/methods/send_photo.py b/aiogram/api/methods/send_photo.py index 2b75b815..89a25864 100644 --- a/aiogram/api/methods/send_photo.py +++ b/aiogram/api/methods/send_photo.py @@ -1,6 +1,7 @@ from typing import Any, Dict, Optional, Union from ..types import ( + UNSET, ForceReply, InlineKeyboardMarkup, InputFile, @@ -30,8 +31,9 @@ class SendPhoto(TelegramMethod[Message]): caption: Optional[str] = None """Photo caption (may also be used when resending photos by file_id), 0-1024 characters after entities parsing""" - parse_mode: Optional[str] = None - """Mode for parsing entities in the photo caption. See formatting options for more details.""" + parse_mode: Optional[str] = UNSET + """Send Markdown or HTML, if you want Telegram apps to show bold, italic, fixed-width text or + inline URLs in the media caption.""" disable_notification: Optional[bool] = None """Sends the message silently. Users will receive a notification with no sound.""" reply_to_message_id: Optional[int] = None diff --git a/aiogram/api/methods/send_video.py b/aiogram/api/methods/send_video.py index 1017b286..f2659348 100644 --- a/aiogram/api/methods/send_video.py +++ b/aiogram/api/methods/send_video.py @@ -1,6 +1,7 @@ from typing import Any, Dict, Optional, Union from ..types import ( + UNSET, ForceReply, InlineKeyboardMarkup, InputFile, @@ -45,8 +46,9 @@ class SendVideo(TelegramMethod[Message]): caption: Optional[str] = None """Video caption (may also be used when resending videos by file_id), 0-1024 characters after entities parsing""" - parse_mode: Optional[str] = None - """Mode for parsing entities in the video caption. See formatting options for more details.""" + parse_mode: Optional[str] = UNSET + """Send Markdown or HTML, if you want Telegram apps to show bold, italic, fixed-width text or + inline URLs in the media caption.""" supports_streaming: Optional[bool] = None """Pass True, if the uploaded video is suitable for streaming""" disable_notification: Optional[bool] = None diff --git a/aiogram/api/methods/send_voice.py b/aiogram/api/methods/send_voice.py index 96e2a159..1369ad1c 100644 --- a/aiogram/api/methods/send_voice.py +++ b/aiogram/api/methods/send_voice.py @@ -1,6 +1,7 @@ from typing import Any, Dict, Optional, Union from ..types import ( + UNSET, ForceReply, InlineKeyboardMarkup, InputFile, @@ -33,9 +34,9 @@ class SendVoice(TelegramMethod[Message]): Internet, or upload a new one using multipart/form-data.""" caption: Optional[str] = None """Voice message caption, 0-1024 characters after entities parsing""" - parse_mode: Optional[str] = None - """Mode for parsing entities in the voice message caption. See formatting options for more - details.""" + parse_mode: Optional[str] = UNSET + """Send Markdown or HTML, if you want Telegram apps to show bold, italic, fixed-width text or + inline URLs in the media caption.""" duration: Optional[int] = None """Duration of the voice message in seconds""" disable_notification: Optional[bool] = None diff --git a/aiogram/api/types/__init__.py b/aiogram/api/types/__init__.py index e5020458..3dbb0439 100644 --- a/aiogram/api/types/__init__.py +++ b/aiogram/api/types/__init__.py @@ -1,6 +1,6 @@ from .animation import Animation from .audio import Audio -from .base import TelegramObject +from .base import UNSET, TelegramObject from .bot_command import BotCommand from .callback_game import CallbackGame from .callback_query import CallbackQuery @@ -103,6 +103,7 @@ from .webhook_info import WebhookInfo __all__ = ( "TelegramObject", "Downloadable", + "UNSET", "BufferedInputFile", "FSInputFile", "URLInputFile", diff --git a/aiogram/api/types/base.py b/aiogram/api/types/base.py index 8c098202..06618234 100644 --- a/aiogram/api/types/base.py +++ b/aiogram/api/types/base.py @@ -1,4 +1,6 @@ import datetime +from typing import Any +from unittest.mock import sentinel from pydantic import BaseModel, Extra @@ -19,3 +21,7 @@ class TelegramObject(ContextInstanceMixin["TelegramObject"], BaseModel): class MutableTelegramObject(TelegramObject): class Config: allow_mutation = True + + +UNSET: Any = sentinel.UNSET # special sentinel object which used in sutuation when None might be a useful value +print(id(UNSET)) diff --git a/aiogram/api/types/inline_query_result_audio.py b/aiogram/api/types/inline_query_result_audio.py index dd4ed624..687de9f0 100644 --- a/aiogram/api/types/inline_query_result_audio.py +++ b/aiogram/api/types/inline_query_result_audio.py @@ -4,6 +4,7 @@ from typing import TYPE_CHECKING, Optional from pydantic import Field +from .base import UNSET from .inline_query_result import InlineQueryResult if TYPE_CHECKING: # pragma: no cover @@ -32,8 +33,9 @@ class InlineQueryResultAudio(InlineQueryResult): """Title""" caption: Optional[str] = None """Caption, 0-1024 characters after entities parsing""" - parse_mode: Optional[str] = None - """Mode for parsing entities in the audio caption. See formatting options for more details.""" + parse_mode: Optional[str] = UNSET + """Send Markdown or HTML, if you want Telegram apps to show bold, italic, fixed-width text or + inline URLs in the media caption.""" performer: Optional[str] = None """Performer""" audio_duration: Optional[int] = None diff --git a/aiogram/api/types/inline_query_result_cached_audio.py b/aiogram/api/types/inline_query_result_cached_audio.py index b1b32880..af508b2e 100644 --- a/aiogram/api/types/inline_query_result_cached_audio.py +++ b/aiogram/api/types/inline_query_result_cached_audio.py @@ -4,6 +4,7 @@ from typing import TYPE_CHECKING, Optional from pydantic import Field +from .base import UNSET from .inline_query_result import InlineQueryResult if TYPE_CHECKING: # pragma: no cover @@ -30,8 +31,9 @@ class InlineQueryResultCachedAudio(InlineQueryResult): """A valid file identifier for the audio file""" caption: Optional[str] = None """Caption, 0-1024 characters after entities parsing""" - parse_mode: Optional[str] = None - """Mode for parsing entities in the audio caption. See formatting options for more details.""" + parse_mode: Optional[str] = UNSET + """Send Markdown or HTML, if you want Telegram apps to show bold, italic, fixed-width text or + inline URLs in the media caption.""" reply_markup: Optional[InlineKeyboardMarkup] = None """Inline keyboard attached to the message""" input_message_content: Optional[InputMessageContent] = None diff --git a/aiogram/api/types/inline_query_result_cached_document.py b/aiogram/api/types/inline_query_result_cached_document.py index 1f377fb7..f9024291 100644 --- a/aiogram/api/types/inline_query_result_cached_document.py +++ b/aiogram/api/types/inline_query_result_cached_document.py @@ -4,6 +4,7 @@ from typing import TYPE_CHECKING, Optional from pydantic import Field +from .base import UNSET from .inline_query_result import InlineQueryResult if TYPE_CHECKING: # pragma: no cover @@ -34,8 +35,9 @@ class InlineQueryResultCachedDocument(InlineQueryResult): """Short description of the result""" caption: Optional[str] = None """Caption of the document to be sent, 0-1024 characters after entities parsing""" - parse_mode: Optional[str] = None - """Mode for parsing entities in the document caption. See formatting options for more details.""" + parse_mode: Optional[str] = UNSET + """Send Markdown or HTML, if you want Telegram apps to show bold, italic, fixed-width text or + inline URLs in the media caption.""" reply_markup: Optional[InlineKeyboardMarkup] = None """Inline keyboard attached to the message""" input_message_content: Optional[InputMessageContent] = None diff --git a/aiogram/api/types/inline_query_result_cached_gif.py b/aiogram/api/types/inline_query_result_cached_gif.py index 228da905..3408a404 100644 --- a/aiogram/api/types/inline_query_result_cached_gif.py +++ b/aiogram/api/types/inline_query_result_cached_gif.py @@ -4,6 +4,7 @@ from typing import TYPE_CHECKING, Optional from pydantic import Field +from .base import UNSET from .inline_query_result import InlineQueryResult if TYPE_CHECKING: # pragma: no cover @@ -30,8 +31,9 @@ class InlineQueryResultCachedGif(InlineQueryResult): """Title for the result""" caption: Optional[str] = None """Caption of the GIF file to be sent, 0-1024 characters after entities parsing""" - parse_mode: Optional[str] = None - """Mode for parsing entities in the caption. See formatting options for more details.""" + parse_mode: Optional[str] = UNSET + """Send Markdown or HTML, if you want Telegram apps to show bold, italic, fixed-width text or + inline URLs in the media caption.""" reply_markup: Optional[InlineKeyboardMarkup] = None """Inline keyboard attached to the message""" input_message_content: Optional[InputMessageContent] = None diff --git a/aiogram/api/types/inline_query_result_cached_mpeg4_gif.py b/aiogram/api/types/inline_query_result_cached_mpeg4_gif.py index 73e9ad2b..71a4e926 100644 --- a/aiogram/api/types/inline_query_result_cached_mpeg4_gif.py +++ b/aiogram/api/types/inline_query_result_cached_mpeg4_gif.py @@ -4,6 +4,7 @@ from typing import TYPE_CHECKING, Optional from pydantic import Field +from .base import UNSET from .inline_query_result import InlineQueryResult if TYPE_CHECKING: # pragma: no cover @@ -31,8 +32,9 @@ class InlineQueryResultCachedMpeg4Gif(InlineQueryResult): """Title for the result""" caption: Optional[str] = None """Caption of the MPEG-4 file to be sent, 0-1024 characters after entities parsing""" - parse_mode: Optional[str] = None - """Mode for parsing entities in the caption. See formatting options for more details.""" + parse_mode: Optional[str] = UNSET + """Send Markdown or HTML, if you want Telegram apps to show bold, italic, fixed-width text or + inline URLs in the media caption.""" reply_markup: Optional[InlineKeyboardMarkup] = None """Inline keyboard attached to the message""" input_message_content: Optional[InputMessageContent] = None diff --git a/aiogram/api/types/inline_query_result_cached_photo.py b/aiogram/api/types/inline_query_result_cached_photo.py index be425a5c..1e7abd57 100644 --- a/aiogram/api/types/inline_query_result_cached_photo.py +++ b/aiogram/api/types/inline_query_result_cached_photo.py @@ -4,6 +4,7 @@ from typing import TYPE_CHECKING, Optional from pydantic import Field +from .base import UNSET from .inline_query_result import InlineQueryResult if TYPE_CHECKING: # pragma: no cover @@ -32,8 +33,9 @@ class InlineQueryResultCachedPhoto(InlineQueryResult): """Short description of the result""" caption: Optional[str] = None """Caption of the photo to be sent, 0-1024 characters after entities parsing""" - parse_mode: Optional[str] = None - """Mode for parsing entities in the photo caption. See formatting options for more details.""" + parse_mode: Optional[str] = UNSET + """Send Markdown or HTML, if you want Telegram apps to show bold, italic, fixed-width text or + inline URLs in the media caption.""" reply_markup: Optional[InlineKeyboardMarkup] = None """Inline keyboard attached to the message""" input_message_content: Optional[InputMessageContent] = None diff --git a/aiogram/api/types/inline_query_result_cached_video.py b/aiogram/api/types/inline_query_result_cached_video.py index 497283e4..b6161679 100644 --- a/aiogram/api/types/inline_query_result_cached_video.py +++ b/aiogram/api/types/inline_query_result_cached_video.py @@ -4,6 +4,7 @@ from typing import TYPE_CHECKING, Optional from pydantic import Field +from .base import UNSET from .inline_query_result import InlineQueryResult if TYPE_CHECKING: # pragma: no cover @@ -32,8 +33,9 @@ class InlineQueryResultCachedVideo(InlineQueryResult): """Short description of the result""" caption: Optional[str] = None """Caption of the video to be sent, 0-1024 characters after entities parsing""" - parse_mode: Optional[str] = None - """Mode for parsing entities in the video caption. See formatting options for more details.""" + parse_mode: Optional[str] = UNSET + """Send Markdown or HTML, if you want Telegram apps to show bold, italic, fixed-width text or + inline URLs in the media caption.""" reply_markup: Optional[InlineKeyboardMarkup] = None """Inline keyboard attached to the message""" input_message_content: Optional[InputMessageContent] = None diff --git a/aiogram/api/types/inline_query_result_cached_voice.py b/aiogram/api/types/inline_query_result_cached_voice.py index c11ecef0..12491b88 100644 --- a/aiogram/api/types/inline_query_result_cached_voice.py +++ b/aiogram/api/types/inline_query_result_cached_voice.py @@ -4,6 +4,7 @@ from typing import TYPE_CHECKING, Optional from pydantic import Field +from .base import UNSET from .inline_query_result import InlineQueryResult if TYPE_CHECKING: # pragma: no cover @@ -32,9 +33,9 @@ class InlineQueryResultCachedVoice(InlineQueryResult): """Voice message title""" caption: Optional[str] = None """Caption, 0-1024 characters after entities parsing""" - parse_mode: Optional[str] = None - """Mode for parsing entities in the voice message caption. See formatting options for more - details.""" + parse_mode: Optional[str] = UNSET + """Send Markdown or HTML, if you want Telegram apps to show bold, italic, fixed-width text or + inline URLs in the media caption.""" reply_markup: Optional[InlineKeyboardMarkup] = None """Inline keyboard attached to the message""" input_message_content: Optional[InputMessageContent] = None diff --git a/aiogram/api/types/inline_query_result_document.py b/aiogram/api/types/inline_query_result_document.py index 207345de..0c66579c 100644 --- a/aiogram/api/types/inline_query_result_document.py +++ b/aiogram/api/types/inline_query_result_document.py @@ -4,6 +4,7 @@ from typing import TYPE_CHECKING, Optional from pydantic import Field +from .base import UNSET from .inline_query_result import InlineQueryResult if TYPE_CHECKING: # pragma: no cover @@ -35,8 +36,9 @@ class InlineQueryResultDocument(InlineQueryResult): """Mime type of the content of the file, either 'application/pdf' or 'application/zip'""" caption: Optional[str] = None """Caption of the document to be sent, 0-1024 characters after entities parsing""" - parse_mode: Optional[str] = None - """Mode for parsing entities in the document caption. See formatting options for more details.""" + parse_mode: Optional[str] = UNSET + """Send Markdown or HTML, if you want Telegram apps to show bold, italic, fixed-width text or + inline URLs in the media caption.""" description: Optional[str] = None """Short description of the result""" reply_markup: Optional[InlineKeyboardMarkup] = None diff --git a/aiogram/api/types/inline_query_result_gif.py b/aiogram/api/types/inline_query_result_gif.py index e428225b..1285b96f 100644 --- a/aiogram/api/types/inline_query_result_gif.py +++ b/aiogram/api/types/inline_query_result_gif.py @@ -4,6 +4,7 @@ from typing import TYPE_CHECKING, Optional from pydantic import Field +from .base import UNSET from .inline_query_result import InlineQueryResult if TYPE_CHECKING: # pragma: no cover @@ -38,8 +39,9 @@ class InlineQueryResultGif(InlineQueryResult): """Title for the result""" caption: Optional[str] = None """Caption of the GIF file to be sent, 0-1024 characters after entities parsing""" - parse_mode: Optional[str] = None - """Mode for parsing entities in the caption. See formatting options for more details.""" + parse_mode: Optional[str] = UNSET + """Send Markdown or HTML, if you want Telegram apps to show bold, italic, fixed-width text or + inline URLs in the media caption.""" reply_markup: Optional[InlineKeyboardMarkup] = None """Inline keyboard attached to the message""" input_message_content: Optional[InputMessageContent] = None diff --git a/aiogram/api/types/inline_query_result_mpeg4_gif.py b/aiogram/api/types/inline_query_result_mpeg4_gif.py index 139dbb30..4fa6a8e9 100644 --- a/aiogram/api/types/inline_query_result_mpeg4_gif.py +++ b/aiogram/api/types/inline_query_result_mpeg4_gif.py @@ -4,6 +4,7 @@ from typing import TYPE_CHECKING, Optional from pydantic import Field +from .base import UNSET from .inline_query_result import InlineQueryResult if TYPE_CHECKING: # pragma: no cover @@ -39,8 +40,9 @@ class InlineQueryResultMpeg4Gif(InlineQueryResult): """Title for the result""" caption: Optional[str] = None """Caption of the MPEG-4 file to be sent, 0-1024 characters after entities parsing""" - parse_mode: Optional[str] = None - """Mode for parsing entities in the caption. See formatting options for more details.""" + parse_mode: Optional[str] = UNSET + """Send Markdown or HTML, if you want Telegram apps to show bold, italic, fixed-width text or + inline URLs in the media caption.""" reply_markup: Optional[InlineKeyboardMarkup] = None """Inline keyboard attached to the message""" input_message_content: Optional[InputMessageContent] = None diff --git a/aiogram/api/types/inline_query_result_photo.py b/aiogram/api/types/inline_query_result_photo.py index e44b63c8..5927c62c 100644 --- a/aiogram/api/types/inline_query_result_photo.py +++ b/aiogram/api/types/inline_query_result_photo.py @@ -4,6 +4,7 @@ from typing import TYPE_CHECKING, Optional from pydantic import Field +from .base import UNSET from .inline_query_result import InlineQueryResult if TYPE_CHECKING: # pragma: no cover @@ -38,8 +39,9 @@ class InlineQueryResultPhoto(InlineQueryResult): """Short description of the result""" caption: Optional[str] = None """Caption of the photo to be sent, 0-1024 characters after entities parsing""" - parse_mode: Optional[str] = None - """Mode for parsing entities in the photo caption. See formatting options for more details.""" + parse_mode: Optional[str] = UNSET + """Send Markdown or HTML, if you want Telegram apps to show bold, italic, fixed-width text or + inline URLs in the media caption.""" reply_markup: Optional[InlineKeyboardMarkup] = None """Inline keyboard attached to the message""" input_message_content: Optional[InputMessageContent] = None diff --git a/aiogram/api/types/inline_query_result_video.py b/aiogram/api/types/inline_query_result_video.py index a025fc4e..5ea390ed 100644 --- a/aiogram/api/types/inline_query_result_video.py +++ b/aiogram/api/types/inline_query_result_video.py @@ -4,6 +4,7 @@ from typing import TYPE_CHECKING, Optional from pydantic import Field +from .base import UNSET from .inline_query_result import InlineQueryResult if TYPE_CHECKING: # pragma: no cover @@ -36,8 +37,9 @@ class InlineQueryResultVideo(InlineQueryResult): """Title for the result""" caption: Optional[str] = None """Caption of the video to be sent, 0-1024 characters after entities parsing""" - parse_mode: Optional[str] = None - """Mode for parsing entities in the video caption. See formatting options for more details.""" + parse_mode: Optional[str] = UNSET + """Send Markdown or HTML, if you want Telegram apps to show bold, italic, fixed-width text or + inline URLs in the media caption.""" video_width: Optional[int] = None """Video width""" video_height: Optional[int] = None diff --git a/aiogram/api/types/inline_query_result_voice.py b/aiogram/api/types/inline_query_result_voice.py index 161eafe8..74d17448 100644 --- a/aiogram/api/types/inline_query_result_voice.py +++ b/aiogram/api/types/inline_query_result_voice.py @@ -4,6 +4,7 @@ from typing import TYPE_CHECKING, Optional from pydantic import Field +from .base import UNSET from .inline_query_result import InlineQueryResult if TYPE_CHECKING: # pragma: no cover @@ -33,9 +34,9 @@ class InlineQueryResultVoice(InlineQueryResult): """Recording title""" caption: Optional[str] = None """Caption, 0-1024 characters after entities parsing""" - parse_mode: Optional[str] = None - """Mode for parsing entities in the voice message caption. See formatting options for more - details.""" + parse_mode: Optional[str] = UNSET + """Send Markdown or HTML, if you want Telegram apps to show bold, italic, fixed-width text or + inline URLs in the media caption.""" voice_duration: Optional[int] = None """Recording duration in seconds""" reply_markup: Optional[InlineKeyboardMarkup] = None diff --git a/aiogram/api/types/input_media_animation.py b/aiogram/api/types/input_media_animation.py index 17523135..e62dc95e 100644 --- a/aiogram/api/types/input_media_animation.py +++ b/aiogram/api/types/input_media_animation.py @@ -4,6 +4,7 @@ from typing import TYPE_CHECKING, Optional, Union from pydantic import Field +from .base import UNSET from .input_media import InputMedia if TYPE_CHECKING: # pragma: no cover @@ -33,9 +34,9 @@ class InputMediaAnimation(InputMedia): multipart/form-data under .""" caption: Optional[str] = None """Caption of the animation to be sent, 0-1024 characters after entities parsing""" - parse_mode: Optional[str] = None - """Mode for parsing entities in the animation caption. See formatting options for more - details.""" + parse_mode: Optional[str] = UNSET + """Send Markdown or HTML, if you want Telegram apps to show bold, italic, fixed-width text or + inline URLs in the media caption.""" width: Optional[int] = None """Animation width""" height: Optional[int] = None diff --git a/aiogram/api/types/input_media_audio.py b/aiogram/api/types/input_media_audio.py index 37162374..40059bd9 100644 --- a/aiogram/api/types/input_media_audio.py +++ b/aiogram/api/types/input_media_audio.py @@ -4,6 +4,7 @@ from typing import TYPE_CHECKING, Optional, Union from pydantic import Field +from .base import UNSET from .input_media import InputMedia if TYPE_CHECKING: # pragma: no cover @@ -33,8 +34,9 @@ class InputMediaAudio(InputMedia): multipart/form-data under .""" caption: Optional[str] = None """Caption of the audio to be sent, 0-1024 characters after entities parsing""" - parse_mode: Optional[str] = None - """Mode for parsing entities in the audio caption. See formatting options for more details.""" + parse_mode: Optional[str] = UNSET + """Send Markdown or HTML, if you want Telegram apps to show bold, italic, fixed-width text or + inline URLs in the media caption.""" duration: Optional[int] = None """Duration of the audio in seconds""" performer: Optional[str] = None diff --git a/aiogram/api/types/input_media_document.py b/aiogram/api/types/input_media_document.py index a3237906..d57f1178 100644 --- a/aiogram/api/types/input_media_document.py +++ b/aiogram/api/types/input_media_document.py @@ -4,6 +4,7 @@ from typing import TYPE_CHECKING, Optional, Union from pydantic import Field +from .base import UNSET from .input_media import InputMedia if TYPE_CHECKING: # pragma: no cover @@ -33,5 +34,6 @@ class InputMediaDocument(InputMedia): multipart/form-data under .""" caption: Optional[str] = None """Caption of the document to be sent, 0-1024 characters after entities parsing""" - parse_mode: Optional[str] = None - """Mode for parsing entities in the document caption. See formatting options for more details.""" + parse_mode: Optional[str] = UNSET + """Send Markdown or HTML, if you want Telegram apps to show bold, italic, fixed-width text or + inline URLs in the media caption.""" diff --git a/aiogram/api/types/input_media_photo.py b/aiogram/api/types/input_media_photo.py index 529a5bc9..c92b45e4 100644 --- a/aiogram/api/types/input_media_photo.py +++ b/aiogram/api/types/input_media_photo.py @@ -4,6 +4,7 @@ from typing import TYPE_CHECKING, Optional, Union from pydantic import Field +from .base import UNSET from .input_media import InputMedia if TYPE_CHECKING: # pragma: no cover @@ -26,5 +27,6 @@ class InputMediaPhoto(InputMedia): name.""" caption: Optional[str] = None """Caption of the photo to be sent, 0-1024 characters after entities parsing""" - parse_mode: Optional[str] = None - """Mode for parsing entities in the photo caption. See formatting options for more details.""" + parse_mode: Optional[str] = UNSET + """Send Markdown or HTML, if you want Telegram apps to show bold, italic, fixed-width text or + inline URLs in the media caption.""" diff --git a/aiogram/api/types/input_media_video.py b/aiogram/api/types/input_media_video.py index 6af1b68c..61e73c1e 100644 --- a/aiogram/api/types/input_media_video.py +++ b/aiogram/api/types/input_media_video.py @@ -4,6 +4,7 @@ from typing import TYPE_CHECKING, Optional, Union from pydantic import Field +from .base import UNSET from .input_media import InputMedia if TYPE_CHECKING: # pragma: no cover @@ -33,8 +34,9 @@ class InputMediaVideo(InputMedia): multipart/form-data under .""" caption: Optional[str] = None """Caption of the video to be sent, 0-1024 characters after entities parsing""" - parse_mode: Optional[str] = None - """Mode for parsing entities in the video caption. See formatting options for more details.""" + parse_mode: Optional[str] = UNSET + """Send Markdown or HTML, if you want Telegram apps to show bold, italic, fixed-width text or + inline URLs in the media caption.""" width: Optional[int] = None """Video width""" height: Optional[int] = None diff --git a/aiogram/api/types/input_text_message_content.py b/aiogram/api/types/input_text_message_content.py index 2a8257cd..3c5bda13 100644 --- a/aiogram/api/types/input_text_message_content.py +++ b/aiogram/api/types/input_text_message_content.py @@ -2,6 +2,7 @@ from __future__ import annotations from typing import Optional +from .base import UNSET from .input_message_content import InputMessageContent @@ -14,7 +15,8 @@ class InputTextMessageContent(InputMessageContent): message_text: str """Text of the message to be sent, 1-4096 characters""" - parse_mode: Optional[str] = None - """Mode for parsing entities in the message text. See formatting options for more details.""" + parse_mode: Optional[str] = UNSET + """Send Markdown or HTML, if you want Telegram apps to show bold, italic, fixed-width text or + inline URLs in your bot's message.""" disable_web_page_preview: Optional[bool] = None """Disables link previews for links in the sent message""" diff --git a/tests/test_api/test_methods/test_base.py b/tests/test_api/test_methods/test_base.py index c32a075b..e3627d54 100644 --- a/tests/test_api/test_methods/test_base.py +++ b/tests/test_api/test_methods/test_base.py @@ -59,4 +59,4 @@ class TestPrepareParseMode: def test_bot_not_in_context(self): data = {} prepare_parse_mode(data) - assert "parse_mode" not in data + assert data["parse_mode"] is None