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

@ -6,7 +6,7 @@ import warnings
from asyncio import Event
from collections import Counter
from contextlib import suppress
from typing import Any, Optional
from typing import Any
from unittest.mock import AsyncMock, patch
import pytest
@ -199,7 +199,7 @@ class TestDispatcher:
async def test_process_update_empty(self, bot: MockedBot):
dispatcher = Dispatcher()
with pytest.warns(RuntimeWarning, match="Detected unknown update type") as record:
with pytest.warns(RuntimeWarning, match="Detected unknown update type"):
result = await dispatcher._process_update(bot=bot, update=Update(update_id=42))
assert not result
@ -819,7 +819,7 @@ class TestDispatcher:
with (
patch(
"aiogram.dispatcher.dispatcher.Dispatcher._process_update", new_callable=AsyncMock
) as mocked_process_update,
),
patch(
"aiogram.dispatcher.dispatcher.Dispatcher._listen_updates"
) as patched_listen_updates,
@ -913,7 +913,7 @@ class TestDispatcher:
patch(
"aiogram.dispatcher.dispatcher.Dispatcher._process_update",
side_effect=mock_process_update,
) as mocked_process_update,
),
patch(
"aiogram.dispatcher.dispatcher.Dispatcher._listen_updates"
) as patched_listen_updates,

View file

@ -1,5 +1,6 @@
import functools
from typing import Any, Callable, Dict, Set, Union
from collections.abc import Callable
from typing import Any
import pytest
from magic_filter import F as A
@ -29,7 +30,7 @@ async def callback4(foo: int, *, bar: int, baz: int):
class TestFilter(Filter):
async def __call__(self, foo: int, bar: int, baz: int) -> Union[bool, Dict[str, Any]]:
async def __call__(self, foo: int, bar: int, baz: int) -> bool | dict[str, Any]:
return locals()
@ -61,7 +62,7 @@ class TestCallableObject:
pytest.param(SyncCallable(), {"foo", "bar", "baz"}),
],
)
def test_init_args_spec(self, callback: Callable, args: Set[str]):
def test_init_args_spec(self, callback: Callable, args: set[str]):
obj = CallableObject(callback)
assert set(obj.params) == args
@ -125,7 +126,7 @@ class TestCallableObject:
],
)
def test_prepare_kwargs(
self, callback: Callable, kwargs: Dict[str, Any], result: Dict[str, Any]
self, callback: Callable, kwargs: dict[str, Any], result: dict[str, Any]
):
obj = CallableObject(callback)
assert obj._prepare_kwargs(kwargs) == result
@ -147,7 +148,6 @@ class TestFilterObject:
def test_post_init(self):
case = F.test
filter_obj = FilterObject(callback=case)
print(filter_obj.callback)
assert filter_obj.callback == case.resolve

View file

@ -1,6 +1,6 @@
import datetime
import functools
from typing import Any, Dict, NoReturn, Optional, Union
from typing import Any, NoReturn
import pytest
from pydantic import BaseModel
@ -31,7 +31,7 @@ async def pipe_handler(*args, **kwargs):
class MyFilter1(Filter, BaseModel):
test: str
async def __call__(self, *args: Any, **kwargs: Any) -> Union[bool, Dict[str, Any]]:
async def __call__(self, *args: Any, **kwargs: Any) -> bool | dict[str, Any]:
return True
@ -44,16 +44,16 @@ class MyFilter3(MyFilter1):
class OptionalFilter(Filter, BaseModel):
optional: Optional[str]
optional: str | None
async def __call__(self, *args: Any, **kwargs: Any) -> Union[bool, Dict[str, Any]]:
async def __call__(self, *args: Any, **kwargs: Any) -> bool | dict[str, Any]:
return True
class DefaultFilter(Filter, BaseModel):
default: str = "Default"
async def __call__(self, *args: Any, **kwargs: Any) -> Union[bool, Dict[str, Any]]:
async def __call__(self, *args: Any, **kwargs: Any) -> bool | dict[str, Any]:
return True