Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add "id" property to State instances #2398

Closed
wants to merge 1 commit into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 5 additions & 1 deletion telebot/states/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,13 @@ class MyStates(StatesGroup):
my_state = State() # returns my_state:State string.
"""

id = 0

def __init__(self) -> None:
self.id = self.__class__.id
self.name: str = None
self.group: StatesGroup = None
self.__class__.id += 1

def __str__(self) -> str:
return f"<{self.name}>"
Expand All @@ -42,7 +46,7 @@ def __init_subclass__(cls) -> None:
and isinstance(value, State)
):
# change value of that variable
value.name = ":".join((cls.__name__, name))
value.name = ":".join((cls.__name__, name, str(value.id)))
value.group = cls
state_list.append(value)
cls._state_list = state_list
Expand Down
Loading