From 2dffa0e3ddc6ea015dfcbf2b2a6450ca96cc1abf Mon Sep 17 00:00:00 2001 From: Yuriy Chebyshev Date: Fri, 8 Jul 2022 15:12:39 +0300 Subject: [PATCH] CR fix: add isinstance check --- aiogram/dispatcher/filters/builtin.py | 6 +++++- tests/test_dispatcher/test_filters/test_builtin.py | 7 +++++++ 2 files changed, 12 insertions(+), 1 deletion(-) diff --git a/aiogram/dispatcher/filters/builtin.py b/aiogram/dispatcher/filters/builtin.py index ffec6017..73530c70 100644 --- a/aiogram/dispatcher/filters/builtin.py +++ b/aiogram/dispatcher/filters/builtin.py @@ -69,7 +69,11 @@ class Command(Filter): if isinstance(commands, (str, BotCommand)): commands = (commands,) elif isinstance(commands, Iterable): - pass + if not all(map(lambda cmd: isinstance(cmd, str), commands)): + raise ValueError( + "Command filter doesn't support {} as input. " + "It only supports str, BotCommand object or their Iterable" + ) else: raise ValueError( "Command filter doesn't support {} as input. " diff --git a/tests/test_dispatcher/test_filters/test_builtin.py b/tests/test_dispatcher/test_filters/test_builtin.py index 3d6ebb78..472a1f7b 100644 --- a/tests/test_dispatcher/test_filters/test_builtin.py +++ b/tests/test_dispatcher/test_filters/test_builtin.py @@ -139,3 +139,10 @@ async def test_commands_filter_not_checked(): start_filter = Command(commands=["help", BotCommand("about", "my desc")]) assert not await start_filter.check(message_with_command) + + +@pytest.mark.asyncio +async def test_commands_filter_not_checked(): + with pytest.raises(ValueError): + start_filter = Command(commands=42) # noqa +