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
|
|
@ -1,32 +1,10 @@
|
|||
from __future__ import annotations
|
||||
|
||||
from typing import TYPE_CHECKING, Any, Optional, Union
|
||||
from typing import TYPE_CHECKING, Any, Optional
|
||||
|
||||
from pydantic import Field
|
||||
|
||||
from ..types import (
|
||||
InlineQueryResultArticle,
|
||||
InlineQueryResultAudio,
|
||||
InlineQueryResultCachedAudio,
|
||||
InlineQueryResultCachedDocument,
|
||||
InlineQueryResultCachedGif,
|
||||
InlineQueryResultCachedMpeg4Gif,
|
||||
InlineQueryResultCachedPhoto,
|
||||
InlineQueryResultCachedSticker,
|
||||
InlineQueryResultCachedVideo,
|
||||
InlineQueryResultCachedVoice,
|
||||
InlineQueryResultContact,
|
||||
InlineQueryResultDocument,
|
||||
InlineQueryResultGame,
|
||||
InlineQueryResultGif,
|
||||
InlineQueryResultLocation,
|
||||
InlineQueryResultMpeg4Gif,
|
||||
InlineQueryResultPhoto,
|
||||
InlineQueryResultsButton,
|
||||
InlineQueryResultVenue,
|
||||
InlineQueryResultVideo,
|
||||
InlineQueryResultVoice,
|
||||
)
|
||||
from ..types import InlineQueryResultsButton, InlineQueryResultUnion
|
||||
from .base import TelegramMethod
|
||||
|
||||
|
||||
|
|
@ -44,30 +22,7 @@ class AnswerInlineQuery(TelegramMethod[bool]):
|
|||
|
||||
inline_query_id: str
|
||||
"""Unique identifier for the answered query"""
|
||||
results: list[
|
||||
Union[
|
||||
InlineQueryResultCachedAudio,
|
||||
InlineQueryResultCachedDocument,
|
||||
InlineQueryResultCachedGif,
|
||||
InlineQueryResultCachedMpeg4Gif,
|
||||
InlineQueryResultCachedPhoto,
|
||||
InlineQueryResultCachedSticker,
|
||||
InlineQueryResultCachedVideo,
|
||||
InlineQueryResultCachedVoice,
|
||||
InlineQueryResultArticle,
|
||||
InlineQueryResultAudio,
|
||||
InlineQueryResultContact,
|
||||
InlineQueryResultGame,
|
||||
InlineQueryResultDocument,
|
||||
InlineQueryResultGif,
|
||||
InlineQueryResultLocation,
|
||||
InlineQueryResultMpeg4Gif,
|
||||
InlineQueryResultPhoto,
|
||||
InlineQueryResultVenue,
|
||||
InlineQueryResultVideo,
|
||||
InlineQueryResultVoice,
|
||||
]
|
||||
]
|
||||
results: list[InlineQueryResultUnion]
|
||||
"""A JSON-serialized array of results for the inline query"""
|
||||
cache_time: Optional[int] = None
|
||||
"""The maximum amount of time in seconds that the result of the inline query may be cached on the server. Defaults to 300."""
|
||||
|
|
@ -96,30 +51,7 @@ class AnswerInlineQuery(TelegramMethod[bool]):
|
|||
__pydantic__self__,
|
||||
*,
|
||||
inline_query_id: str,
|
||||
results: list[
|
||||
Union[
|
||||
InlineQueryResultCachedAudio,
|
||||
InlineQueryResultCachedDocument,
|
||||
InlineQueryResultCachedGif,
|
||||
InlineQueryResultCachedMpeg4Gif,
|
||||
InlineQueryResultCachedPhoto,
|
||||
InlineQueryResultCachedSticker,
|
||||
InlineQueryResultCachedVideo,
|
||||
InlineQueryResultCachedVoice,
|
||||
InlineQueryResultArticle,
|
||||
InlineQueryResultAudio,
|
||||
InlineQueryResultContact,
|
||||
InlineQueryResultGame,
|
||||
InlineQueryResultDocument,
|
||||
InlineQueryResultGif,
|
||||
InlineQueryResultLocation,
|
||||
InlineQueryResultMpeg4Gif,
|
||||
InlineQueryResultPhoto,
|
||||
InlineQueryResultVenue,
|
||||
InlineQueryResultVideo,
|
||||
InlineQueryResultVoice,
|
||||
]
|
||||
],
|
||||
results: list[InlineQueryResultUnion],
|
||||
cache_time: Optional[int] = None,
|
||||
is_personal: Optional[bool] = None,
|
||||
next_offset: Optional[str] = None,
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue