mirror of
https://github.com/eternnoir/pyTelegramBotAPI.git
synced 2023-08-10 21:12:57 +03:00
Define state_list in __init_subclass__
This commit is contained in:
parent
d466da3542
commit
e4bddd91cb
@ -74,17 +74,18 @@ class StatesGroup:
|
||||
my_state = State() # returns my_state:State string.
|
||||
"""
|
||||
def __init_subclass__(cls) -> None:
|
||||
|
||||
state_list = []
|
||||
for name, value in cls.__dict__.items():
|
||||
if not name.startswith('__') and not callable(value) and isinstance(value, State):
|
||||
# change value of that variable
|
||||
value.name = ':'.join((cls.__name__, name))
|
||||
value.group = cls
|
||||
state_list.append(value)
|
||||
cls._state_list = state_list
|
||||
|
||||
@property
|
||||
def state_list(self):
|
||||
return [value for name, value in self.__dict__.items()
|
||||
if not name.startswith('__') and not callable(value) and isinstance(value, State)]
|
||||
return self._state_list
|
||||
|
||||
|
||||
class SkipHandler:
|
||||
|
@ -185,16 +185,18 @@ class StatesGroup:
|
||||
my_state = State() # returns my_state:State string.
|
||||
"""
|
||||
def __init_subclass__(cls) -> None:
|
||||
state_list = []
|
||||
for name, value in cls.__dict__.items():
|
||||
if not name.startswith('__') and not callable(value) and isinstance(value, State):
|
||||
# change value of that variable
|
||||
value.name = ':'.join((cls.__name__, name))
|
||||
value.group = cls
|
||||
state_list.append(value)
|
||||
cls._state_list = state_list
|
||||
|
||||
@property
|
||||
def state_list(self):
|
||||
return [value for name, value in self.__dict__.items()
|
||||
if not name.startswith('__') and not callable(value) and isinstance(value, State)]
|
||||
return self._state_list
|
||||
|
||||
|
||||
class BaseMiddleware:
|
||||
|
Loading…
Reference in New Issue
Block a user