diff --git a/aiogram/dispatcher/fsm/state.py b/aiogram/dispatcher/fsm/state.py index e6a204f8..6c49d63b 100644 --- a/aiogram/dispatcher/fsm/state.py +++ b/aiogram/dispatcher/fsm/state.py @@ -1,5 +1,5 @@ import inspect -from typing import Any, Dict, Iterator, Optional, Tuple, Type, no_type_check +from typing import Any, Iterator, Optional, Tuple, Type, no_type_check from ...types import TelegramObject @@ -54,18 +54,17 @@ class State: return True return raw_state == self.state - def __eq__(self, other): + def __eq__(self, other: Any) -> bool: if isinstance(other, self.__class__): 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") - def __hash__(self): + def __hash__(self) -> int: return hash(self.state) - class StatesGroupMeta(type): __parent__: "Optional[Type[StatesGroup]]" __childs__: "Tuple[Type[StatesGroup], ...]" diff --git a/tests/test_dispatcher/test_filters/test_state.py b/tests/test_dispatcher/test_filters/test_state.py index f1e7c037..5f74d091 100644 --- a/tests/test_dispatcher/test_filters/test_state.py +++ b/tests/test_dispatcher/test_filters/test_state.py @@ -58,3 +58,14 @@ class TestStateFilter: state = State() assert SG.state == copy(SG.state) + + assert SG.state == "SG:state" + assert "SG:state" == SG.state + + assert State() == State() + + with pytest.raises(ValueError): + assert SG.state == 1 + + states = {SG.state: "OK"} + assert states.get(copy(SG.state)) == "OK"