mirror of
https://github.com/aiogram/aiogram.git
synced 2026-04-08 16:37:47 +00:00
Refactor: Introduce Union types for streamlined type handling (#1649)
* Refactor: Introduce Union types for streamlined type handling Implemented Union types across various modules to consolidate and simplify type annotations. This change replaces repetitive union declarations with reusable Union aliases, improving code readability and maintainability. Updates applied to affected classes, methods, and imports accordingly. * Refactor unions into type aliases for better reusability Replaced inline `Union` types with predefined aliases like `MediaUnion`, `ReplyMarkupUnion`, and `ChatIdUnion`. Simplifies type annotations, improves code readability, and reduces duplication. Added `media_union.py` for grouping related media types. * Refactor type unions with ResultChatMemberUnion and ResultMenuButtonUnion Replaced verbose type definitions of chat member and menu button unions with `ResultChatMemberUnion` and `ResultMenuButtonUnion` for improved readability and maintainability. Updated relevant methods, modules, and documentation to use the new type aliases consistently. * Added changelog
This commit is contained in:
parent
843c1dec7c
commit
cd4e811856
173 changed files with 1452 additions and 2562 deletions
|
|
@ -6,13 +6,11 @@ from pydantic import Field
|
|||
|
||||
from ..client.default import Default
|
||||
from ..types import (
|
||||
ForceReply,
|
||||
InlineKeyboardMarkup,
|
||||
InputFile,
|
||||
ChatIdUnion,
|
||||
InputFileUnion,
|
||||
Message,
|
||||
MessageEntity,
|
||||
ReplyKeyboardMarkup,
|
||||
ReplyKeyboardRemove,
|
||||
ReplyMarkupUnion,
|
||||
ReplyParameters,
|
||||
)
|
||||
from .base import TelegramMethod
|
||||
|
|
@ -28,9 +26,9 @@ class SendPhoto(TelegramMethod[Message]):
|
|||
__returning__ = Message
|
||||
__api_method__ = "sendPhoto"
|
||||
|
||||
chat_id: Union[int, str]
|
||||
chat_id: ChatIdUnion
|
||||
"""Unique identifier for the target chat or username of the target channel (in the format :code:`@channelusername`)"""
|
||||
photo: Union[InputFile, str]
|
||||
photo: InputFileUnion
|
||||
"""Photo to send. Pass a file_id as String to send a photo that exists on the Telegram servers (recommended), pass an HTTP URL as a String for Telegram to get a photo from the Internet, or upload a new photo using multipart/form-data. The photo must be at most 10 MB in size. The photo's width and height must not exceed 10000 in total. Width and height ratio must be at most 20. :ref:`More information on Sending Files » <sending-files>`"""
|
||||
business_connection_id: Optional[str] = None
|
||||
"""Unique identifier of the business connection on behalf of which the message will be sent"""
|
||||
|
|
@ -56,9 +54,7 @@ class SendPhoto(TelegramMethod[Message]):
|
|||
"""Unique identifier of the message effect to be added to the message; for private chats only"""
|
||||
reply_parameters: Optional[ReplyParameters] = None
|
||||
"""Description of the message to reply to"""
|
||||
reply_markup: Optional[
|
||||
Union[InlineKeyboardMarkup, ReplyKeyboardMarkup, ReplyKeyboardRemove, ForceReply]
|
||||
] = None
|
||||
reply_markup: Optional[ReplyMarkupUnion] = None
|
||||
"""Additional interface options. A JSON-serialized object for an `inline keyboard <https://core.telegram.org/bots/features#inline-keyboards>`_, `custom reply keyboard <https://core.telegram.org/bots/features#keyboards>`_, instructions to remove a reply keyboard or to force a reply from the user"""
|
||||
allow_sending_without_reply: Optional[bool] = Field(
|
||||
None, json_schema_extra={"deprecated": True}
|
||||
|
|
@ -80,8 +76,8 @@ class SendPhoto(TelegramMethod[Message]):
|
|||
def __init__(
|
||||
__pydantic__self__,
|
||||
*,
|
||||
chat_id: Union[int, str],
|
||||
photo: Union[InputFile, str],
|
||||
chat_id: ChatIdUnion,
|
||||
photo: InputFileUnion,
|
||||
business_connection_id: Optional[str] = None,
|
||||
message_thread_id: Optional[int] = None,
|
||||
caption: Optional[str] = None,
|
||||
|
|
@ -96,9 +92,7 @@ class SendPhoto(TelegramMethod[Message]):
|
|||
allow_paid_broadcast: Optional[bool] = None,
|
||||
message_effect_id: Optional[str] = None,
|
||||
reply_parameters: Optional[ReplyParameters] = None,
|
||||
reply_markup: Optional[
|
||||
Union[InlineKeyboardMarkup, ReplyKeyboardMarkup, ReplyKeyboardRemove, ForceReply]
|
||||
] = None,
|
||||
reply_markup: Optional[ReplyMarkupUnion] = None,
|
||||
allow_sending_without_reply: Optional[bool] = None,
|
||||
reply_to_message_id: Optional[int] = None,
|
||||
**__pydantic_kwargs: Any,
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue