diff --git a/aiogram/dispatcher/fsm/state.py b/aiogram/dispatcher/fsm/state.py index d4ea1974..a04d5516 100644 --- a/aiogram/dispatcher/fsm/state.py +++ b/aiogram/dispatcher/fsm/state.py @@ -118,6 +118,9 @@ class StatesGroupMeta(type): def __str__(self) -> str: return f"" + def __iter__(self): + return iter(self.__all_states__) + class StatesGroup(metaclass=StatesGroupMeta): @classmethod diff --git a/tests/test_dispatcher/test_fsm/test_state.py b/tests/test_dispatcher/test_fsm/test_state.py index 07037e86..c89f158f 100644 --- a/tests/test_dispatcher/test_fsm/test_state.py +++ b/tests/test_dispatcher/test_fsm/test_state.py @@ -150,3 +150,10 @@ class TestStatesGroup: assert 42 not in MyGroup assert MyGroup.MyNestedGroup.get_root() is MyGroup + + def test_iterable(self): + class Group(StatesGroup): + x = State() + y = State() + + assert set(Group) == {Group.x, Group.y}