Fixed #1217: Fixed union subtypes generation inside arrays of elements

This commit is contained in:
Alex Root Junior 2023-07-17 00:10:47 +03:00
parent 0ed62bcadf
commit 21351de335
No known key found for this signature in database
GPG key ID: 074C1D455EBEA4AC
7 changed files with 183 additions and 19 deletions

View file

@ -140,7 +140,6 @@ from ..methods import (
from ..types import (
UNSET_PARSE_MODE,
BotCommand,
BotCommandScope,
BotCommandScopeAllChatAdministrators,
BotCommandScopeAllGroupChats,
BotCommandScopeAllPrivateChats,
@ -167,7 +166,6 @@ from ..types import (
ForumTopic,
GameHighScore,
InlineKeyboardMarkup,
InlineQueryResult,
InlineQueryResultArticle,
InlineQueryResultAudio,
InlineQueryResultCachedAudio,
@ -190,7 +188,6 @@ from ..types import (
InlineQueryResultVideo,
InlineQueryResultVoice,
InputFile,
InputMedia,
InputMediaAnimation,
InputMediaAudio,
InputMediaDocument,
@ -205,7 +202,15 @@ from ..types import (
Message,
MessageEntity,
MessageId,
PassportElementError,
PassportElementErrorDataField,
PassportElementErrorFile,
PassportElementErrorFiles,
PassportElementErrorFrontSide,
PassportElementErrorReverseSide,
PassportElementErrorSelfie,
PassportElementErrorTranslationFile,
PassportElementErrorTranslationFiles,
PassportElementErrorUnspecified,
Poll,
ReplyKeyboardMarkup,
ReplyKeyboardRemove,
@ -509,7 +514,30 @@ class Bot(ContextInstanceMixin["Bot"]):
async def answer_inline_query(
self,
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,
is_personal: Optional[bool] = None,
next_offset: Optional[str] = None,
@ -3368,7 +3396,19 @@ class Bot(ContextInstanceMixin["Bot"]):
async def set_passport_data_errors(
self,
user_id: int,
errors: List[PassportElementError],
errors: List[
Union[
PassportElementErrorDataField,
PassportElementErrorFrontSide,
PassportElementErrorReverseSide,
PassportElementErrorSelfie,
PassportElementErrorFile,
PassportElementErrorFiles,
PassportElementErrorTranslationFile,
PassportElementErrorTranslationFiles,
PassportElementErrorUnspecified,
]
],
request_timeout: Optional[int] = None,
) -> bool:
"""

View file

@ -1,10 +1,32 @@
from __future__ import annotations
from typing import List, Optional
from typing import List, Optional, Union
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
@ -22,7 +44,30 @@ class AnswerInlineQuery(TelegramMethod[bool]):
inline_query_id: str
"""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"""
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."""

View file

@ -1,8 +1,18 @@
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
@ -19,5 +29,17 @@ class SetPassportDataErrors(TelegramMethod[bool]):
user_id: int
"""User identifier"""
errors: List[PassportElementError]
errors: List[
Union[
PassportElementErrorDataField,
PassportElementErrorFrontSide,
PassportElementErrorReverseSide,
PassportElementErrorSelfie,
PassportElementErrorFile,
PassportElementErrorFiles,
PassportElementErrorTranslationFile,
PassportElementErrorTranslationFiles,
PassportElementErrorUnspecified,
]
]
"""A JSON-serialized array describing the errors"""

View file

@ -1,6 +1,6 @@
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
@ -8,7 +8,26 @@ from .base import TelegramObject
if TYPE_CHECKING:
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 .location import Location
from .user import User
@ -36,7 +55,30 @@ class InlineQuery(TelegramObject):
def answer(
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,
is_personal: Optional[bool] = None,
next_offset: Optional[str] = None,

View file

@ -149,7 +149,7 @@ features = [
"test",
]
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]

View file

@ -2,6 +2,7 @@ from aiogram import Bot
from aiogram.methods import AnswerInlineQuery, Request
from aiogram.types import (
InlineQueryResult,
InlineQueryResultArticle,
InlineQueryResultPhoto,
InputTextMessageContent,
)
@ -13,7 +14,14 @@ class TestAnswerInlineQuery:
prepare_result = bot.add_result_for(AnswerInlineQuery, ok=True, result=True)
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()
assert response == prepare_result.result

View file

@ -1,5 +1,5 @@
from aiogram.methods import Request, SetPassportDataErrors
from aiogram.types import PassportElementError
from aiogram.types import PassportElementError, PassportElementErrorFile
from tests.mocked_bot import MockedBot
@ -8,7 +8,14 @@ class TestSetPassportDataErrors:
prepare_result = bot.add_result_for(SetPassportDataErrors, ok=True, result=True)
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()
assert response == prepare_result.result