From c952a730c2e2ea12d1746c4a4f3ea97b8976f890 Mon Sep 17 00:00:00 2001 From: darksidecat Date: Sun, 26 Jun 2022 14:35:11 +0300 Subject: [PATCH] return False for not equal objects creating FilterObject use getfullargspec that check State equality with `type` and `object` builtins, raising Error in `__eq__` method of State break this behavior --- aiogram/dispatcher/fsm/state.py | 2 +- tests/test_dispatcher/test_filters/test_state.py | 9 ++++++--- 2 files changed, 7 insertions(+), 4 deletions(-) diff --git a/aiogram/dispatcher/fsm/state.py b/aiogram/dispatcher/fsm/state.py index 6c49d63b..5a4f4075 100644 --- a/aiogram/dispatcher/fsm/state.py +++ b/aiogram/dispatcher/fsm/state.py @@ -59,7 +59,7 @@ class State: return self.state == other.state if isinstance(other, str): return self.state == other - raise ValueError(f"Comparing {type(self)} and {type(other)} is not supported") + return False def __hash__(self) -> int: return hash(self.state) diff --git a/tests/test_dispatcher/test_filters/test_state.py b/tests/test_dispatcher/test_filters/test_state.py index 5f74d091..1e68346e 100644 --- a/tests/test_dispatcher/test_filters/test_state.py +++ b/tests/test_dispatcher/test_filters/test_state.py @@ -3,6 +3,7 @@ from inspect import isclass import pytest +from aiogram.dispatcher.event.handler import FilterObject from aiogram.dispatcher.filters import StateFilter from aiogram.dispatcher.fsm.state import State, StatesGroup from aiogram.types import Update @@ -52,6 +53,10 @@ class TestStateFilter: f = StateFilter(state=state) assert bool(await f(obj=Update(update_id=42), raw_state=current_state)) is result + @pytestmark + async def test_create_filter_from_state(self): + FilterObject(callback=State(state="state")) + @pytestmark async def test_state_copy(self): class SG(StatesGroup): @@ -63,9 +68,7 @@ class TestStateFilter: assert "SG:state" == SG.state assert State() == State() - - with pytest.raises(ValueError): - assert SG.state == 1 + assert not SG.state == 1 states = {SG.state: "OK"} assert states.get(copy(SG.state)) == "OK"