Skip to content

Commit

Permalink
Bump dev dependencies (#1512)
Browse files Browse the repository at this point in the history
* Bump dev dependencies

* Pre-commit py3.8 support

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

* Mute mypy python version bug
  • Loading branch information
Olegt0rr committed Jun 14, 2024
1 parent 0df95a0 commit 7760ab1
Show file tree
Hide file tree
Showing 20 changed files with 92 additions and 75 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ jobs:
- name: Lint code
run: |
ruff --output-format=github aiogram examples
ruff check --output-format=github aiogram examples
mypy aiogram
black --check --diff aiogram tests
Expand Down
9 changes: 4 additions & 5 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
repos:
- repo: https://github.com/pre-commit/pre-commit-hooks
rev: v4.2.0
rev: v4.6.0
hooks:
- id: "trailing-whitespace"
- id: "check-case-conflict"
Expand All @@ -14,13 +14,12 @@ repos:
- id: "check-json"

- repo: https://github.com/psf/black
rev: 22.10.0
rev: 24.4.2
hooks:
- id: black
files: &files '^(aiogram|tests|examples)'

- repo: https://github.com/charliermarsh/ruff-pre-commit
rev: 'v0.0.215'
- repo: https://github.com/astral-sh/ruff-pre-commit
rev: 'v0.4.9'
hooks:
- id: ruff
args: [ "--force-exclude" ]
7 changes: 6 additions & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,11 @@ clean:
rm -f .coverage
rm -rf {build,dist,site,.cache,.mypy_cache,.ruff_cache,reports}

.PHONY: install
install: clean
pip install -e ."[dev,test,docs]" -U --upgrade-strategy=eager
pre-commit install

# =================================================================================================
# Code quality
# =================================================================================================
Expand All @@ -34,7 +39,7 @@ clean:
lint:
isort --check-only $(code_dir)
black --check --diff $(code_dir)
ruff $(package_dir)
ruff check $(package_dir) $(examples_dir)
mypy $(package_dir)

.PHONY: reformat
Expand Down
5 changes: 4 additions & 1 deletion aiogram/client/session/middlewares/manager.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,10 @@ def unregister(self, middleware: RequestMiddlewareType) -> None:
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)
Expand Down
2 changes: 1 addition & 1 deletion aiogram/dispatcher/middlewares/manager.py
Original file line number Diff line number Diff line change
Expand Up @@ -61,5 +61,5 @@ def handler_wrapper(event: TelegramObject, kwargs: Dict[str, Any]) -> Any:

middleware = handler_wrapper
for m in reversed(middlewares):
middleware = functools.partial(m, middleware)
middleware = functools.partial(m, middleware) # type: ignore[assignment]
return middleware
40 changes: 24 additions & 16 deletions aiogram/dispatcher/middlewares/user_context.py
Original file line number Diff line number Diff line change
Expand Up @@ -57,17 +57,19 @@ def resolve_event_context(cls, event: Update) -> EventContext:
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)
Expand All @@ -82,10 +84,12 @@ def resolve_event_context(cls, event: Update) -> EventContext:
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:
Expand Down Expand Up @@ -132,18 +136,22 @@ def resolve_event_context(cls, event: Update) -> EventContext:
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()
5 changes: 3 additions & 2 deletions aiogram/filters/command.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,14 @@
import re
from dataclasses import dataclass, field, replace
from typing import (
TYPE_CHECKING,
Any,
Dict,
Iterable,
Match,
Optional,
Pattern,
Sequence,
TYPE_CHECKING,
Union,
cast,
)
Expand All @@ -24,7 +24,8 @@
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):
Expand Down
4 changes: 2 additions & 2 deletions aiogram/types/bot_command_scope_all_chat_administrators.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
4 changes: 2 additions & 2 deletions aiogram/types/bot_command_scope_chat_administrators.py
Original file line number Diff line number Diff line change
Expand Up @@ -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`)"""
Expand Down
4 changes: 2 additions & 2 deletions aiogram/types/passport_element_error_translation_file.py
Original file line number Diff line number Diff line change
Expand Up @@ -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'"""
Expand Down
4 changes: 2 additions & 2 deletions aiogram/types/passport_element_error_translation_files.py
Original file line number Diff line number Diff line change
Expand Up @@ -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'"""
Expand Down
3 changes: 1 addition & 2 deletions aiogram/utils/keyboard.py
Original file line number Diff line number Diff line change
Expand Up @@ -397,8 +397,7 @@ def button(

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)
Expand Down
8 changes: 5 additions & 3 deletions aiogram/utils/media_group.py
Original file line number Diff line number Diff line change
Expand Up @@ -359,8 +359,10 @@ def build(self) -> List[MediaType]:
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)
]
1 change: 1 addition & 0 deletions aiogram/utils/payload.py
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,7 @@ def decrypt(self, data: bytes) -> bytes:
# result: decoded == "foo"
"""

from base64 import urlsafe_b64decode, urlsafe_b64encode
from typing import Callable, Optional

Expand Down
2 changes: 1 addition & 1 deletion examples/context_addition_from_filter.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ def __init__(self, name: Optional[str] = None) -> None:
async def __call__(
self,
message: Message,
event_from_user: User
event_from_user: User,
# Filters also can accept keyword parameters like in handlers
) -> Union[bool, Dict[str, Any]]:
if message.text.casefold() == "hello":
Expand Down
1 change: 1 addition & 0 deletions examples/echo_bot_webhook.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
"""
This example shows how to use webhook on behind of any reverse proxy (nginx, traefik, ingress etc.)
"""

import logging
import sys
from os import getenv
Expand Down
1 change: 1 addition & 0 deletions examples/echo_bot_webhook_ssl.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
"""
This example shows how to use webhook with SSL certificate.
"""

import logging
import ssl
import sys
Expand Down
3 changes: 1 addition & 2 deletions examples/own_filter.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,5 +14,4 @@ async def __call__(self, message: Message) -> bool:


@router.message(MyFilter("hello"))
async def my_handler(message: Message):
...
async def my_handler(message: Message): ...
50 changes: 26 additions & 24 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -101,13 +101,13 @@ docs = [
"sphinxcontrib-towncrier~=0.3.2a0",
]
dev = [
"black~=23.10.0",
"isort~=5.12.0",
"ruff~=0.1.1",
"mypy~=1.6.1",
"black~=24.4.2",
"isort~=5.13.2",
"ruff~=0.4.9",
"mypy~=1.10.0",
"toml~=0.10.2",
"pre-commit~=3.5.0",
"packaging~=23.1",
"pre-commit~=3.5",
"packaging~=24.1",
"motor-types~=1.0.0b4",
]

Expand All @@ -132,10 +132,10 @@ post-install-commands = [

[tool.hatch.envs.default.scripts]
reformat = [
"black aiogram tests",
"isort aiogram tests",
"black aiogram tests examples",
"isort aiogram tests examples",
]
lint = "ruff aiogram"
lint = "ruff check aiogram tests examples"

[tool.hatch.envs.docs]
features = [
Expand Down Expand Up @@ -202,19 +202,6 @@ python = ["38", "39", "310", "311", "312"]

[tool.ruff]
line-length = 99
select = [
# "C", # TODO: mccabe - code complecity
"C4",
"E",
"F",
"T10",
"T20",
"Q",
"RET",
]
ignore = [
"F401"
]
src = ["aiogram", "tests"]
exclude = [
".git",
Expand All @@ -230,15 +217,30 @@ exclude = [
]
target-version = "py310"

[tool.ruff.isort]
[tool.ruff.lint]
select = [
# "C", # TODO: mccabe - code complecity
"C4",
"E",
"F",
"T10",
"T20",
"Q",
"RET",
]
ignore = [
"F401"
]

[tool.ruff.lint.isort]
known-first-party = [
"aiogram",
"finite_state_machine",
"handlers",
"routes",
]

[tool.ruff.per-file-ignores]
[tool.ruff.lint.per-file-ignores]
"aiogram/client/bot.py" = ["E501"]
"aiogram/types/*" = ["E501"]
"aiogram/methods/*" = ["E501"]
Expand Down
12 changes: 4 additions & 8 deletions tests/test_dispatcher/test_dispatcher.py
Original file line number Diff line number Diff line change
Expand Up @@ -992,17 +992,13 @@ async def test_feed_webhook_update_fast_process_error(self, bot: MockedBot, capl
pytest.fail("Expected 'Detected slow response into webhook' warning.")

def test_specify_updates_calculation(self):
def simple_msg_handler() -> None:
...
def simple_msg_handler() -> None: ...

def simple_callback_query_handler() -> None:
...
def simple_callback_query_handler() -> None: ...

def simple_poll_handler() -> None:
...
def simple_poll_handler() -> None: ...

def simple_edited_msg_handler() -> None:
...
def simple_edited_msg_handler() -> None: ...

dispatcher = Dispatcher()
dispatcher.message.register(simple_msg_handler)
Expand Down

0 comments on commit 7760ab1

Please sign in to comment.