Skip to content

Commit 370f037

Browse files
Merge pull request eternnoir#1964 from Cub11k/add_state_list
Add state_list to StatesGroup
2 parents e64c06b + e4bddd9 commit 370f037

File tree

2 files changed

+15
-2
lines changed

2 files changed

+15
-2
lines changed

telebot/asyncio_handler_backends.py

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -74,12 +74,18 @@ class MyStates(StatesGroup):
7474
my_state = State() # returns my_state:State string.
7575
"""
7676
def __init_subclass__(cls) -> None:
77-
77+
state_list = []
7878
for name, value in cls.__dict__.items():
7979
if not name.startswith('__') and not callable(value) and isinstance(value, State):
8080
# change value of that variable
8181
value.name = ':'.join((cls.__name__, name))
8282
value.group = cls
83+
state_list.append(value)
84+
cls._state_list = state_list
85+
86+
@property
87+
def state_list(self):
88+
return self._state_list
8389

8490

8591
class SkipHandler:

telebot/handler_backends.py

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -185,13 +185,20 @@ class MyStates(StatesGroup):
185185
my_state = State() # returns my_state:State string.
186186
"""
187187
def __init_subclass__(cls) -> None:
188+
state_list = []
188189
for name, value in cls.__dict__.items():
189190
if not name.startswith('__') and not callable(value) and isinstance(value, State):
190191
# change value of that variable
191192
value.name = ':'.join((cls.__name__, name))
192193
value.group = cls
194+
state_list.append(value)
195+
cls._state_list = state_list
196+
197+
@property
198+
def state_list(self):
199+
return self._state_list
200+
193201

194-
195202
class BaseMiddleware:
196203
"""
197204
Base class for middleware.

0 commit comments

Comments
 (0)