Bump dev dependencies (#1512)

* Bump dev dependencies

* Pre-commit py3.8 support

* Pre-commit py3.8 support (v3.5+)

* Mute mypy python version bug
This commit is contained in:
Oleg A 2024-06-14 20:11:08 +03:00 committed by GitHub
parent 0df95a0276
commit 7760ab1d0d
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
20 changed files with 92 additions and 75 deletions

View file

@ -27,7 +27,10 @@ class RequestMiddlewareManager(Sequence[RequestMiddlewareType]):
def __call__(
self,
middleware: Optional[RequestMiddlewareType] = None,
) -> Union[Callable[[RequestMiddlewareType], RequestMiddlewareType], RequestMiddlewareType,]:
) -> Union[
Callable[[RequestMiddlewareType], RequestMiddlewareType],
RequestMiddlewareType,
]:
if middleware is None:
return self.register
return self.register(middleware)

View file

@ -61,5 +61,5 @@ class MiddlewareManager(Sequence[MiddlewareType[TelegramObject]]):
middleware = handler_wrapper
for m in reversed(middlewares):
middleware = functools.partial(m, middleware)
middleware = functools.partial(m, middleware) # type: ignore[assignment]
return middleware

View file

@ -57,17 +57,19 @@ class UserContextMiddleware(BaseMiddleware):
return EventContext(
chat=event.message.chat,
user=event.message.from_user,
thread_id=event.message.message_thread_id
if event.message.is_topic_message
else None,
thread_id=(
event.message.message_thread_id if event.message.is_topic_message else None
),
)
if event.edited_message:
return EventContext(
chat=event.edited_message.chat,
user=event.edited_message.from_user,
thread_id=event.edited_message.message_thread_id
if event.edited_message.is_topic_message
else None,
thread_id=(
event.edited_message.message_thread_id
if event.edited_message.is_topic_message
else None
),
)
if event.channel_post:
return EventContext(chat=event.channel_post.chat)
@ -82,10 +84,12 @@ class UserContextMiddleware(BaseMiddleware):
return EventContext(
chat=event.callback_query.message.chat,
user=event.callback_query.from_user,
thread_id=event.callback_query.message.message_thread_id
if not isinstance(event.callback_query.message, InaccessibleMessage)
and event.callback_query.message.is_topic_message
else None,
thread_id=(
event.callback_query.message.message_thread_id
if not isinstance(event.callback_query.message, InaccessibleMessage)
and event.callback_query.message.is_topic_message
else None
),
)
return EventContext(user=event.callback_query.from_user)
if event.shipping_query:
@ -132,18 +136,22 @@ class UserContextMiddleware(BaseMiddleware):
return EventContext(
chat=event.business_message.chat,
user=event.business_message.from_user,
thread_id=event.business_message.message_thread_id
if event.business_message.is_topic_message
else None,
thread_id=(
event.business_message.message_thread_id
if event.business_message.is_topic_message
else None
),
business_connection_id=event.business_message.business_connection_id,
)
if event.edited_business_message:
return EventContext(
chat=event.edited_business_message.chat,
user=event.edited_business_message.from_user,
thread_id=event.edited_business_message.message_thread_id
if event.edited_business_message.is_topic_message
else None,
thread_id=(
event.edited_business_message.message_thread_id
if event.edited_business_message.is_topic_message
else None
),
business_connection_id=event.edited_business_message.business_connection_id,
)
return EventContext()

View file

@ -3,7 +3,6 @@ from __future__ import annotations
import re
from dataclasses import dataclass, field, replace
from typing import (
TYPE_CHECKING,
Any,
Dict,
Iterable,
@ -11,6 +10,7 @@ from typing import (
Optional,
Pattern,
Sequence,
TYPE_CHECKING,
Union,
cast,
)
@ -24,7 +24,8 @@ from aiogram.utils.deep_linking import decode_payload
if TYPE_CHECKING:
from aiogram import Bot
CommandPatternType = Union[str, re.Pattern, BotCommand]
# TODO: rm type ignore after py3.8 support expiration or mypy bug fix
CommandPatternType = Union[str, re.Pattern, BotCommand] # type: ignore[type-arg]
class CommandException(Exception):

View file

@ -13,9 +13,9 @@ class BotCommandScopeAllChatAdministrators(BotCommandScope):
Source: https://core.telegram.org/bots/api#botcommandscopeallchatadministrators
"""
type: Literal[
type: Literal[BotCommandScopeType.ALL_CHAT_ADMINISTRATORS] = (
BotCommandScopeType.ALL_CHAT_ADMINISTRATORS
] = BotCommandScopeType.ALL_CHAT_ADMINISTRATORS
)
"""Scope type, must be *all_chat_administrators*"""
if TYPE_CHECKING:

View file

@ -13,9 +13,9 @@ class BotCommandScopeChatAdministrators(BotCommandScope):
Source: https://core.telegram.org/bots/api#botcommandscopechatadministrators
"""
type: Literal[
type: Literal[BotCommandScopeType.CHAT_ADMINISTRATORS] = (
BotCommandScopeType.CHAT_ADMINISTRATORS
] = BotCommandScopeType.CHAT_ADMINISTRATORS
)
"""Scope type, must be *chat_administrators*"""
chat_id: Union[int, str]
"""Unique identifier for the target chat or username of the target supergroup (in the format :code:`@supergroupusername`)"""

View file

@ -13,9 +13,9 @@ class PassportElementErrorTranslationFile(PassportElementError):
Source: https://core.telegram.org/bots/api#passportelementerrortranslationfile
"""
source: Literal[
source: Literal[PassportElementErrorType.TRANSLATION_FILE] = (
PassportElementErrorType.TRANSLATION_FILE
] = PassportElementErrorType.TRANSLATION_FILE
)
"""Error source, must be *translation_file*"""
type: str
"""Type of element of the user's Telegram Passport which has the issue, one of 'passport', 'driver_license', 'identity_card', 'internal_passport', 'utility_bill', 'bank_statement', 'rental_agreement', 'passport_registration', 'temporary_registration'"""

View file

@ -13,9 +13,9 @@ class PassportElementErrorTranslationFiles(PassportElementError):
Source: https://core.telegram.org/bots/api#passportelementerrortranslationfiles
"""
source: Literal[
source: Literal[PassportElementErrorType.TRANSLATION_FILES] = (
PassportElementErrorType.TRANSLATION_FILES
] = PassportElementErrorType.TRANSLATION_FILES
)
"""Error source, must be *translation_files*"""
type: str
"""Type of element of the user's Telegram Passport which has the issue, one of 'passport', 'driver_license', 'identity_card', 'internal_passport', 'utility_bill', 'bank_statement', 'rental_agreement', 'passport_registration', 'temporary_registration'"""

View file

@ -397,8 +397,7 @@ class ReplyKeyboardBuilder(KeyboardBuilder[KeyboardButton]):
if TYPE_CHECKING:
def as_markup(self, **kwargs: Any) -> ReplyKeyboardMarkup:
...
def as_markup(self, **kwargs: Any) -> ReplyKeyboardMarkup: ...
def __init__(self, markup: Optional[List[List[KeyboardButton]]] = None) -> None:
super().__init__(button_type=KeyboardButton, markup=markup)

View file

@ -359,8 +359,10 @@ class MediaGroupBuilder:
update_first_media["parse_mode"] = None
return [
media.model_copy(update=update_first_media)
if index == 0 and self.caption is not None
else media
(
media.model_copy(update=update_first_media)
if index == 0 and self.caption is not None
else media
)
for index, media in enumerate(self._media)
]

View file

@ -60,6 +60,7 @@ Encoding and decoding with your own methods:
# result: decoded == "foo"
"""
from base64 import urlsafe_b64decode, urlsafe_b64encode
from typing import Callable, Optional