Migrate from Black to Ruff (#1750)

* Migrate from Black to Ruff and reformat code with enabling additional linter checks

* Add changelog for migration to Ruff as formatter and linter

* Add type ignores for specific attributes and replace tuple with set for chat type check

* Remove file from another changes
This commit is contained in:
Alex Root Junior 2026-01-04 21:34:08 +02:00 committed by GitHub
parent a4a3f42c71
commit ec7da0f678
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
214 changed files with 886 additions and 964 deletions

View file

@ -9,10 +9,15 @@ class TestBackoffConfig:
@pytest.mark.parametrize(
"kwargs",
[
dict(min_delay=1.0, max_delay=1.0, factor=2.0, jitter=0.1), # equals min and max
dict(min_delay=1.0, max_delay=1.0, factor=1.0, jitter=0.1), # factor == 1
dict(min_delay=1.0, max_delay=2.0, factor=0.5, jitter=0.1), # factor < 1
dict(min_delay=2.0, max_delay=1.0, factor=2.0, jitter=0.1), # min > max
{
"min_delay": 1.0,
"max_delay": 1.0,
"factor": 2.0,
"jitter": 0.1,
}, # equals min and max
{"min_delay": 1.0, "max_delay": 1.0, "factor": 1.0, "jitter": 0.1}, # factor == 1
{"min_delay": 1.0, "max_delay": 2.0, "factor": 0.5, "jitter": 0.1}, # factor < 1
{"min_delay": 2.0, "max_delay": 1.0, "factor": 2.0, "jitter": 0.1}, # min > max
],
)
def test_incorrect_post_init(self, kwargs):
@ -21,7 +26,7 @@ class TestBackoffConfig:
@pytest.mark.parametrize(
"kwargs",
[dict(min_delay=1.0, max_delay=2.0, factor=1.2, jitter=0.1)],
[{"min_delay": 1.0, "max_delay": 2.0, "factor": 1.2, "jitter": 0.1}],
)
def test_correct_post_init(self, kwargs):
assert BackoffConfig(**kwargs)

View file

@ -1,5 +1,4 @@
from datetime import datetime
from typing import Type
import pytest
@ -90,6 +89,6 @@ CHAT_MEMBER_RESTRICTED = ChatMemberRestricted(
(CHAT_MEMBER_RESTRICTED, ChatMemberRestricted),
],
)
def test_chat_member_resolution(data: dict, resolved_type: Type[ChatMember]) -> None:
def test_chat_member_resolution(data: dict, resolved_type: type[ChatMember]) -> None:
chat_member = ChatMemberAdapter.validate_python(data)
assert isinstance(chat_member, resolved_type)

View file

@ -31,7 +31,6 @@ class TestDataclassKwargs:
)
def test_dataclass_kwargs(self, py_version, expected):
with patch("sys.version_info", py_version):
assert (
dataclass_kwargs(
init=True,

View file

@ -1,5 +1,4 @@
from pathlib import Path
from typing import Any, Dict
from typing import Any
import pytest
@ -81,7 +80,7 @@ class TestI18nCore:
["it", {"singular": "test", "plural": "test2", "n": 2}, "test2"],
],
)
def test_gettext(self, i18n: I18n, locale: str, case: Dict[str, Any], result: str):
def test_gettext(self, i18n: I18n, locale: str, case: dict[str, Any], result: str):
if locale is not None:
i18n.current_locale = locale
with i18n.context():

View file

@ -207,21 +207,21 @@ class TestKeyboardBuilder:
markup = builder.export()
assert len(markup) == len(shape)
for row, expected_size in zip(markup, shape):
for row, expected_size in zip(markup, shape, strict=False):
assert len(row) == expected_size
@pytest.mark.parametrize(
"builder_type,kwargs,expected",
[
[ReplyKeyboardBuilder, dict(text="test"), KeyboardButton(text="test")],
[ReplyKeyboardBuilder, {"text": "test"}, KeyboardButton(text="test")],
[
InlineKeyboardBuilder,
dict(text="test", callback_data="callback"),
{"text": "test", "callback_data": "callback"},
InlineKeyboardButton(text="test", callback_data="callback"),
],
[
InlineKeyboardBuilder,
dict(text="test", callback_data=MyCallback(value="test")),
{"text": "test", "callback_data": MyCallback(value="test")},
InlineKeyboardButton(text="test", callback_data="test:test"),
],
],

View file

@ -1,5 +1,5 @@
from itertools import product
from typing import Any, Dict
from typing import Any
from urllib.parse import parse_qs
import pytest
@ -18,7 +18,7 @@ class TestLink:
"base,params,result",
[["user", {"id": 42}, "tg://user?id=42"]],
)
def test_create_tg_link(self, base: str, params: Dict[str, Any], result: str):
def test_create_tg_link(self, base: str, params: dict[str, Any], result: str):
assert create_tg_link(base, **params) == result
@pytest.mark.parametrize(
@ -28,7 +28,7 @@ class TestLink:
["username", {"start": "test"}, "https://t.me/username?start=test"],
],
)
def test_create_telegram_link(self, base: str, params: Dict[str, Any], result: str):
def test_create_telegram_link(self, base: str, params: dict[str, Any], result: str):
assert create_telegram_link(base, **params) == result
def test_fragment(self):
@ -70,8 +70,8 @@ class TestCreateChannelBotLink:
}
variants = product([True, False], repeat=len(params))
for index, variants in enumerate(variants):
kwargs = {k: v for k, v in zip(params, variants) if v}
for _index, variants in enumerate(variants):
kwargs = {k: v for k, v in zip(params, variants, strict=False) if v}
if not kwargs:
# Variant without additional arguments is already covered
continue

View file

@ -1,4 +1,5 @@
from typing import Any, Callable, Optional, Tuple
from collections.abc import Callable
from typing import Any
import pytest
@ -75,6 +76,6 @@ class TestMarkdown:
],
)
def test_formatter(
self, func: Callable[[Any], Any], args: Tuple[str], sep: Optional[str], result: str
self, func: Callable[[Any], Any], args: tuple[str], sep: str | None, result: str
):
assert func(*args, **({"sep": sep} if sep is not None else {})) == result # type: ignore

View file

@ -1,5 +1,3 @@
from typing import List, Optional
import pytest
from aiogram.types import MessageEntity, User
@ -304,7 +302,7 @@ class TestTextDecoration:
self,
decorator: TextDecoration,
text: str,
entities: Optional[List[MessageEntity]],
entities: list[MessageEntity] | None,
result: str,
):
assert decorator.unparse(text, entities) == result