From 6aaeafcd160ef74f2be591e1e304d541c18d93f8 Mon Sep 17 00:00:00 2001 From: Artin GH <80193492+Artin-GH@users.noreply.github.com> Date: Fri, 20 Sep 2024 14:26:39 +0330 Subject: [PATCH] Add "id" property to State instances --- telebot/states/__init__.py | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/telebot/states/__init__.py b/telebot/states/__init__.py index 2491608ee..5bd8c92e2 100644 --- a/telebot/states/__init__.py +++ b/telebot/states/__init__.py @@ -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}>" @@ -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