mirror of
https://github.com/aiogram/aiogram.git
synced 2026-04-08 16:37:47 +00:00
iter states in states group
This commit is contained in:
parent
9451a085d1
commit
31ab2cab5e
2 changed files with 10 additions and 0 deletions
|
|
@ -118,6 +118,9 @@ class StatesGroupMeta(type):
|
|||
def __str__(self) -> str:
|
||||
return f"<StatesGroup '{self.__full_group_name__}'>"
|
||||
|
||||
def __iter__(self):
|
||||
return iter(self.__all_states__)
|
||||
|
||||
|
||||
class StatesGroup(metaclass=StatesGroupMeta):
|
||||
@classmethod
|
||||
|
|
|
|||
|
|
@ -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}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue