From 19a6131618f6724f91011516f208c975a63be407 Mon Sep 17 00:00:00 2001 From: m-xim <170838360+m-xim@users.noreply.github.com> Date: Sat, 4 Apr 2026 01:42:04 +0300 Subject: [PATCH] Remove redundant list() around sorted() and fix router type name in validation error message (#1788) * Remove redundant list() around sorted() * Fix type name in error message for router type validation * Add changelog --- CHANGES/1788.bugfix.rst | 1 + aiogram/dispatcher/router.py | 6 +++--- tests/test_dispatcher/test_router.py | 4 +++- 3 files changed, 7 insertions(+), 4 deletions(-) create mode 100644 CHANGES/1788.bugfix.rst diff --git a/CHANGES/1788.bugfix.rst b/CHANGES/1788.bugfix.rst new file mode 100644 index 00000000..fada2dce --- /dev/null +++ b/CHANGES/1788.bugfix.rst @@ -0,0 +1 @@ +Remove redundant list() around sorted() and fix router type name in validation error message diff --git a/aiogram/dispatcher/router.py b/aiogram/dispatcher/router.py index 532018d5..dde35c3c 100644 --- a/aiogram/dispatcher/router.py +++ b/aiogram/dispatcher/router.py @@ -133,7 +133,7 @@ class Router: Is useful for getting updates only for registered event types. :param skip_events: skip specified event names - :return: set of registered names + :return: sorted list of registered names """ handlers_in_use: set[str] = set() if skip_events is None: @@ -145,7 +145,7 @@ class Router: if observer.handlers and update_name not in skip_events: handlers_in_use.add(update_name) - return list(sorted(handlers_in_use)) # NOQA: C413 + return sorted(handlers_in_use) async def propagate_event(self, update_type: str, event: TelegramObject, **kwargs: Any) -> Any: kwargs.update(event_router=self) @@ -264,7 +264,7 @@ class Router: :return: """ if not isinstance(router, Router): - msg = f"router should be instance of Router not {type(router).__class__.__name__}" + msg = f"router should be instance of Router not {type(router).__name__!r}" raise ValueError(msg) router.parent_router = self return router diff --git a/tests/test_dispatcher/test_router.py b/tests/test_dispatcher/test_router.py index 712786b1..2c9f7820 100644 --- a/tests/test_dispatcher/test_router.py +++ b/tests/test_dispatcher/test_router.py @@ -50,7 +50,9 @@ class TestRouter: def test_include_router_by_string_bad_type(self): router = Router() - with pytest.raises(ValueError, match=r"router should be instance of Router"): + with pytest.raises( + ValueError, match=r"router should be instance of Router not 'TestRouter'" + ): router.include_router(self) def test_set_parent_router_bad_type(self):