mirror of
https://github.com/aiogram/aiogram.git
synced 2026-04-08 16:37:47 +00:00
iter states in states group (#666)
* iter states in states group * fix type hint * remove empty line * add changes for doc
This commit is contained in:
parent
714ac8896c
commit
90b3a99039
3 changed files with 13 additions and 1 deletions
2
CHANGES/666.feature
Normal file
2
CHANGES/666.feature
Normal file
|
|
@ -0,0 +1,2 @@
|
|||
Ability to iterate over all states in StatesGroup.
|
||||
Aiogram already had in check for states group so this is relative feature.
|
||||
|
|
@ -1,5 +1,5 @@
|
|||
import inspect
|
||||
from typing import Any, Optional, Tuple, Type, no_type_check
|
||||
from typing import Any, Iterator, Optional, Tuple, Type, no_type_check
|
||||
|
||||
from ...types import TelegramObject
|
||||
|
||||
|
|
@ -118,6 +118,9 @@ class StatesGroupMeta(type):
|
|||
def __str__(self) -> str:
|
||||
return f"<StatesGroup '{self.__full_group_name__}'>"
|
||||
|
||||
def __iter__(self) -> Iterator[State]:
|
||||
return iter(self.__all_states__)
|
||||
|
||||
|
||||
class StatesGroup(metaclass=StatesGroupMeta):
|
||||
@classmethod
|
||||
|
|
|
|||
|
|
@ -150,6 +150,13 @@ class TestStatesGroup:
|
|||
|
||||
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}
|
||||
|
||||
def test_empty_filter(self):
|
||||
class MyGroup(StatesGroup):
|
||||
pass
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue