mirror of
https://github.com/aiogram/aiogram.git
synced 2025-12-11 09:55:21 +00:00
Implement __contains__ method for states group
This commit is contained in:
parent
8a8749dd02
commit
58154915de
1 changed files with 16 additions and 0 deletions
|
|
@ -91,6 +91,13 @@ class MetaStatesGroup(type):
|
|||
def childs(cls):
|
||||
return cls._childs
|
||||
|
||||
@property
|
||||
def all_childs(cls):
|
||||
result = cls.childs
|
||||
for child in cls.childs:
|
||||
result += child.childs
|
||||
return result
|
||||
|
||||
@property
|
||||
def all_states(cls):
|
||||
result = cls.states
|
||||
|
|
@ -106,6 +113,15 @@ class MetaStatesGroup(type):
|
|||
def states_names(cls) -> tuple:
|
||||
return tuple(state.state for state in cls.states)
|
||||
|
||||
def __contains__(cls, item):
|
||||
if isinstance(item, str):
|
||||
return item in cls.all_states_names
|
||||
elif isinstance(item, State):
|
||||
return item in cls.all_states
|
||||
elif isinstance(item, StatesGroup):
|
||||
return item in cls.all_childs
|
||||
return False
|
||||
|
||||
def __str__(self):
|
||||
return f"<StatesGroup '{self.__full_group_name__}'>"
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue