mirror of
https://github.com/aiogram/aiogram.git
synced 2026-04-08 16:37:47 +00:00
Fixed #1217: Fixed union subtypes generation inside arrays of elements
This commit is contained in:
parent
0ed62bcadf
commit
21351de335
7 changed files with 183 additions and 19 deletions
|
|
@ -140,7 +140,6 @@ from ..methods import (
|
||||||
from ..types import (
|
from ..types import (
|
||||||
UNSET_PARSE_MODE,
|
UNSET_PARSE_MODE,
|
||||||
BotCommand,
|
BotCommand,
|
||||||
BotCommandScope,
|
|
||||||
BotCommandScopeAllChatAdministrators,
|
BotCommandScopeAllChatAdministrators,
|
||||||
BotCommandScopeAllGroupChats,
|
BotCommandScopeAllGroupChats,
|
||||||
BotCommandScopeAllPrivateChats,
|
BotCommandScopeAllPrivateChats,
|
||||||
|
|
@ -167,7 +166,6 @@ from ..types import (
|
||||||
ForumTopic,
|
ForumTopic,
|
||||||
GameHighScore,
|
GameHighScore,
|
||||||
InlineKeyboardMarkup,
|
InlineKeyboardMarkup,
|
||||||
InlineQueryResult,
|
|
||||||
InlineQueryResultArticle,
|
InlineQueryResultArticle,
|
||||||
InlineQueryResultAudio,
|
InlineQueryResultAudio,
|
||||||
InlineQueryResultCachedAudio,
|
InlineQueryResultCachedAudio,
|
||||||
|
|
@ -190,7 +188,6 @@ from ..types import (
|
||||||
InlineQueryResultVideo,
|
InlineQueryResultVideo,
|
||||||
InlineQueryResultVoice,
|
InlineQueryResultVoice,
|
||||||
InputFile,
|
InputFile,
|
||||||
InputMedia,
|
|
||||||
InputMediaAnimation,
|
InputMediaAnimation,
|
||||||
InputMediaAudio,
|
InputMediaAudio,
|
||||||
InputMediaDocument,
|
InputMediaDocument,
|
||||||
|
|
@ -205,7 +202,15 @@ from ..types import (
|
||||||
Message,
|
Message,
|
||||||
MessageEntity,
|
MessageEntity,
|
||||||
MessageId,
|
MessageId,
|
||||||
PassportElementError,
|
PassportElementErrorDataField,
|
||||||
|
PassportElementErrorFile,
|
||||||
|
PassportElementErrorFiles,
|
||||||
|
PassportElementErrorFrontSide,
|
||||||
|
PassportElementErrorReverseSide,
|
||||||
|
PassportElementErrorSelfie,
|
||||||
|
PassportElementErrorTranslationFile,
|
||||||
|
PassportElementErrorTranslationFiles,
|
||||||
|
PassportElementErrorUnspecified,
|
||||||
Poll,
|
Poll,
|
||||||
ReplyKeyboardMarkup,
|
ReplyKeyboardMarkup,
|
||||||
ReplyKeyboardRemove,
|
ReplyKeyboardRemove,
|
||||||
|
|
@ -509,7 +514,30 @@ class Bot(ContextInstanceMixin["Bot"]):
|
||||||
async def answer_inline_query(
|
async def answer_inline_query(
|
||||||
self,
|
self,
|
||||||
inline_query_id: str,
|
inline_query_id: str,
|
||||||
results: List[InlineQueryResult],
|
results: List[
|
||||||
|
Union[
|
||||||
|
InlineQueryResultCachedAudio,
|
||||||
|
InlineQueryResultCachedDocument,
|
||||||
|
InlineQueryResultCachedGif,
|
||||||
|
InlineQueryResultCachedMpeg4Gif,
|
||||||
|
InlineQueryResultCachedPhoto,
|
||||||
|
InlineQueryResultCachedSticker,
|
||||||
|
InlineQueryResultCachedVideo,
|
||||||
|
InlineQueryResultCachedVoice,
|
||||||
|
InlineQueryResultArticle,
|
||||||
|
InlineQueryResultAudio,
|
||||||
|
InlineQueryResultContact,
|
||||||
|
InlineQueryResultGame,
|
||||||
|
InlineQueryResultDocument,
|
||||||
|
InlineQueryResultGif,
|
||||||
|
InlineQueryResultLocation,
|
||||||
|
InlineQueryResultMpeg4Gif,
|
||||||
|
InlineQueryResultPhoto,
|
||||||
|
InlineQueryResultVenue,
|
||||||
|
InlineQueryResultVideo,
|
||||||
|
InlineQueryResultVoice,
|
||||||
|
]
|
||||||
|
],
|
||||||
cache_time: Optional[int] = None,
|
cache_time: Optional[int] = None,
|
||||||
is_personal: Optional[bool] = None,
|
is_personal: Optional[bool] = None,
|
||||||
next_offset: Optional[str] = None,
|
next_offset: Optional[str] = None,
|
||||||
|
|
@ -3368,7 +3396,19 @@ class Bot(ContextInstanceMixin["Bot"]):
|
||||||
async def set_passport_data_errors(
|
async def set_passport_data_errors(
|
||||||
self,
|
self,
|
||||||
user_id: int,
|
user_id: int,
|
||||||
errors: List[PassportElementError],
|
errors: List[
|
||||||
|
Union[
|
||||||
|
PassportElementErrorDataField,
|
||||||
|
PassportElementErrorFrontSide,
|
||||||
|
PassportElementErrorReverseSide,
|
||||||
|
PassportElementErrorSelfie,
|
||||||
|
PassportElementErrorFile,
|
||||||
|
PassportElementErrorFiles,
|
||||||
|
PassportElementErrorTranslationFile,
|
||||||
|
PassportElementErrorTranslationFiles,
|
||||||
|
PassportElementErrorUnspecified,
|
||||||
|
]
|
||||||
|
],
|
||||||
request_timeout: Optional[int] = None,
|
request_timeout: Optional[int] = None,
|
||||||
) -> bool:
|
) -> bool:
|
||||||
"""
|
"""
|
||||||
|
|
|
||||||
|
|
@ -1,10 +1,32 @@
|
||||||
from __future__ import annotations
|
from __future__ import annotations
|
||||||
|
|
||||||
from typing import List, Optional
|
from typing import List, Optional, Union
|
||||||
|
|
||||||
from pydantic import Field
|
from pydantic import Field
|
||||||
|
|
||||||
from ..types import InlineQueryResult, InlineQueryResultsButton
|
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 .base import TelegramMethod
|
from .base import TelegramMethod
|
||||||
|
|
||||||
|
|
||||||
|
|
@ -22,7 +44,30 @@ class AnswerInlineQuery(TelegramMethod[bool]):
|
||||||
|
|
||||||
inline_query_id: str
|
inline_query_id: str
|
||||||
"""Unique identifier for the answered query"""
|
"""Unique identifier for the answered query"""
|
||||||
results: List[InlineQueryResult]
|
results: List[
|
||||||
|
Union[
|
||||||
|
InlineQueryResultCachedAudio,
|
||||||
|
InlineQueryResultCachedDocument,
|
||||||
|
InlineQueryResultCachedGif,
|
||||||
|
InlineQueryResultCachedMpeg4Gif,
|
||||||
|
InlineQueryResultCachedPhoto,
|
||||||
|
InlineQueryResultCachedSticker,
|
||||||
|
InlineQueryResultCachedVideo,
|
||||||
|
InlineQueryResultCachedVoice,
|
||||||
|
InlineQueryResultArticle,
|
||||||
|
InlineQueryResultAudio,
|
||||||
|
InlineQueryResultContact,
|
||||||
|
InlineQueryResultGame,
|
||||||
|
InlineQueryResultDocument,
|
||||||
|
InlineQueryResultGif,
|
||||||
|
InlineQueryResultLocation,
|
||||||
|
InlineQueryResultMpeg4Gif,
|
||||||
|
InlineQueryResultPhoto,
|
||||||
|
InlineQueryResultVenue,
|
||||||
|
InlineQueryResultVideo,
|
||||||
|
InlineQueryResultVoice,
|
||||||
|
]
|
||||||
|
]
|
||||||
"""A JSON-serialized array of results for the inline query"""
|
"""A JSON-serialized array of results for the inline query"""
|
||||||
cache_time: Optional[int] = None
|
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."""
|
"""The maximum amount of time in seconds that the result of the inline query may be cached on the server. Defaults to 300."""
|
||||||
|
|
|
||||||
|
|
@ -1,8 +1,18 @@
|
||||||
from __future__ import annotations
|
from __future__ import annotations
|
||||||
|
|
||||||
from typing import List
|
from typing import List, Union
|
||||||
|
|
||||||
from ..types import PassportElementError
|
from ..types import (
|
||||||
|
PassportElementErrorDataField,
|
||||||
|
PassportElementErrorFile,
|
||||||
|
PassportElementErrorFiles,
|
||||||
|
PassportElementErrorFrontSide,
|
||||||
|
PassportElementErrorReverseSide,
|
||||||
|
PassportElementErrorSelfie,
|
||||||
|
PassportElementErrorTranslationFile,
|
||||||
|
PassportElementErrorTranslationFiles,
|
||||||
|
PassportElementErrorUnspecified,
|
||||||
|
)
|
||||||
from .base import TelegramMethod
|
from .base import TelegramMethod
|
||||||
|
|
||||||
|
|
||||||
|
|
@ -19,5 +29,17 @@ class SetPassportDataErrors(TelegramMethod[bool]):
|
||||||
|
|
||||||
user_id: int
|
user_id: int
|
||||||
"""User identifier"""
|
"""User identifier"""
|
||||||
errors: List[PassportElementError]
|
errors: List[
|
||||||
|
Union[
|
||||||
|
PassportElementErrorDataField,
|
||||||
|
PassportElementErrorFrontSide,
|
||||||
|
PassportElementErrorReverseSide,
|
||||||
|
PassportElementErrorSelfie,
|
||||||
|
PassportElementErrorFile,
|
||||||
|
PassportElementErrorFiles,
|
||||||
|
PassportElementErrorTranslationFile,
|
||||||
|
PassportElementErrorTranslationFiles,
|
||||||
|
PassportElementErrorUnspecified,
|
||||||
|
]
|
||||||
|
]
|
||||||
"""A JSON-serialized array describing the errors"""
|
"""A JSON-serialized array describing the errors"""
|
||||||
|
|
|
||||||
|
|
@ -1,6 +1,6 @@
|
||||||
from __future__ import annotations
|
from __future__ import annotations
|
||||||
|
|
||||||
from typing import TYPE_CHECKING, Any, List, Optional
|
from typing import TYPE_CHECKING, Any, List, Optional, Union
|
||||||
|
|
||||||
from pydantic import Field
|
from pydantic import Field
|
||||||
|
|
||||||
|
|
@ -8,7 +8,26 @@ from .base import TelegramObject
|
||||||
|
|
||||||
if TYPE_CHECKING:
|
if TYPE_CHECKING:
|
||||||
from ..methods import AnswerInlineQuery
|
from ..methods import AnswerInlineQuery
|
||||||
from .inline_query_result import InlineQueryResult
|
from .inline_query_result_article import InlineQueryResultArticle
|
||||||
|
from .inline_query_result_audio import InlineQueryResultAudio
|
||||||
|
from .inline_query_result_cached_audio import InlineQueryResultCachedAudio
|
||||||
|
from .inline_query_result_cached_document import InlineQueryResultCachedDocument
|
||||||
|
from .inline_query_result_cached_gif import InlineQueryResultCachedGif
|
||||||
|
from .inline_query_result_cached_mpeg4_gif import InlineQueryResultCachedMpeg4Gif
|
||||||
|
from .inline_query_result_cached_photo import InlineQueryResultCachedPhoto
|
||||||
|
from .inline_query_result_cached_sticker import InlineQueryResultCachedSticker
|
||||||
|
from .inline_query_result_cached_video import InlineQueryResultCachedVideo
|
||||||
|
from .inline_query_result_cached_voice import InlineQueryResultCachedVoice
|
||||||
|
from .inline_query_result_contact import InlineQueryResultContact
|
||||||
|
from .inline_query_result_document import InlineQueryResultDocument
|
||||||
|
from .inline_query_result_game import InlineQueryResultGame
|
||||||
|
from .inline_query_result_gif import InlineQueryResultGif
|
||||||
|
from .inline_query_result_location import InlineQueryResultLocation
|
||||||
|
from .inline_query_result_mpeg4_gif import InlineQueryResultMpeg4Gif
|
||||||
|
from .inline_query_result_photo import InlineQueryResultPhoto
|
||||||
|
from .inline_query_result_venue import InlineQueryResultVenue
|
||||||
|
from .inline_query_result_video import InlineQueryResultVideo
|
||||||
|
from .inline_query_result_voice import InlineQueryResultVoice
|
||||||
from .inline_query_results_button import InlineQueryResultsButton
|
from .inline_query_results_button import InlineQueryResultsButton
|
||||||
from .location import Location
|
from .location import Location
|
||||||
from .user import User
|
from .user import User
|
||||||
|
|
@ -36,7 +55,30 @@ class InlineQuery(TelegramObject):
|
||||||
|
|
||||||
def answer(
|
def answer(
|
||||||
self,
|
self,
|
||||||
results: List[InlineQueryResult],
|
results: List[
|
||||||
|
Union[
|
||||||
|
InlineQueryResultCachedAudio,
|
||||||
|
InlineQueryResultCachedDocument,
|
||||||
|
InlineQueryResultCachedGif,
|
||||||
|
InlineQueryResultCachedMpeg4Gif,
|
||||||
|
InlineQueryResultCachedPhoto,
|
||||||
|
InlineQueryResultCachedSticker,
|
||||||
|
InlineQueryResultCachedVideo,
|
||||||
|
InlineQueryResultCachedVoice,
|
||||||
|
InlineQueryResultArticle,
|
||||||
|
InlineQueryResultAudio,
|
||||||
|
InlineQueryResultContact,
|
||||||
|
InlineQueryResultGame,
|
||||||
|
InlineQueryResultDocument,
|
||||||
|
InlineQueryResultGif,
|
||||||
|
InlineQueryResultLocation,
|
||||||
|
InlineQueryResultMpeg4Gif,
|
||||||
|
InlineQueryResultPhoto,
|
||||||
|
InlineQueryResultVenue,
|
||||||
|
InlineQueryResultVideo,
|
||||||
|
InlineQueryResultVoice,
|
||||||
|
]
|
||||||
|
],
|
||||||
cache_time: Optional[int] = None,
|
cache_time: Optional[int] = None,
|
||||||
is_personal: Optional[bool] = None,
|
is_personal: Optional[bool] = None,
|
||||||
next_offset: Optional[str] = None,
|
next_offset: Optional[str] = None,
|
||||||
|
|
|
||||||
|
|
@ -149,7 +149,7 @@ features = [
|
||||||
"test",
|
"test",
|
||||||
]
|
]
|
||||||
extra-dependencies = [
|
extra-dependencies = [
|
||||||
"butcher @ git+https://github.com/aiogram/butcher.git@v0.1.16"
|
"butcher @ git+https://github.com/aiogram/butcher.git@v0.1.17"
|
||||||
]
|
]
|
||||||
|
|
||||||
[tool.hatch.envs.dev.scripts]
|
[tool.hatch.envs.dev.scripts]
|
||||||
|
|
|
||||||
|
|
@ -2,6 +2,7 @@ from aiogram import Bot
|
||||||
from aiogram.methods import AnswerInlineQuery, Request
|
from aiogram.methods import AnswerInlineQuery, Request
|
||||||
from aiogram.types import (
|
from aiogram.types import (
|
||||||
InlineQueryResult,
|
InlineQueryResult,
|
||||||
|
InlineQueryResultArticle,
|
||||||
InlineQueryResultPhoto,
|
InlineQueryResultPhoto,
|
||||||
InputTextMessageContent,
|
InputTextMessageContent,
|
||||||
)
|
)
|
||||||
|
|
@ -13,7 +14,14 @@ class TestAnswerInlineQuery:
|
||||||
prepare_result = bot.add_result_for(AnswerInlineQuery, ok=True, result=True)
|
prepare_result = bot.add_result_for(AnswerInlineQuery, ok=True, result=True)
|
||||||
|
|
||||||
response: bool = await bot.answer_inline_query(
|
response: bool = await bot.answer_inline_query(
|
||||||
inline_query_id="query id", results=[InlineQueryResult()]
|
inline_query_id="query id",
|
||||||
|
results=[
|
||||||
|
InlineQueryResultArticle(
|
||||||
|
id="1",
|
||||||
|
title="title",
|
||||||
|
input_message_content=InputTextMessageContent(message_text="text"),
|
||||||
|
)
|
||||||
|
],
|
||||||
)
|
)
|
||||||
request = bot.get_request()
|
request = bot.get_request()
|
||||||
assert response == prepare_result.result
|
assert response == prepare_result.result
|
||||||
|
|
|
||||||
|
|
@ -1,5 +1,5 @@
|
||||||
from aiogram.methods import Request, SetPassportDataErrors
|
from aiogram.methods import Request, SetPassportDataErrors
|
||||||
from aiogram.types import PassportElementError
|
from aiogram.types import PassportElementError, PassportElementErrorFile
|
||||||
from tests.mocked_bot import MockedBot
|
from tests.mocked_bot import MockedBot
|
||||||
|
|
||||||
|
|
||||||
|
|
@ -8,7 +8,14 @@ class TestSetPassportDataErrors:
|
||||||
prepare_result = bot.add_result_for(SetPassportDataErrors, ok=True, result=True)
|
prepare_result = bot.add_result_for(SetPassportDataErrors, ok=True, result=True)
|
||||||
|
|
||||||
response: bool = await bot.set_passport_data_errors(
|
response: bool = await bot.set_passport_data_errors(
|
||||||
user_id=42, errors=[PassportElementError()]
|
user_id=42,
|
||||||
|
errors=[
|
||||||
|
PassportElementErrorFile(
|
||||||
|
type="type",
|
||||||
|
file_hash="hash",
|
||||||
|
message="message",
|
||||||
|
)
|
||||||
|
],
|
||||||
)
|
)
|
||||||
request = bot.get_request()
|
request = bot.get_request()
|
||||||
assert response == prepare_result.result
|
assert response == prepare_result.result
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue