I have several child classes in my code, and there is a specific attribute for which I don't want any child classes to have the same value. Let's call this attribute command_name
I tried to implement that using init_subclasses :
class Parent:
    list_of_unique_values_command_name = list()
    def __init_subclass__(cls, **kwargs):
        super().__init_subclass__(**kwargs)
        if hasattr(cls, "command_name"):
            if cls.command_name in Parent.list_of_unique_values_command_name:
                raise ValueError("cant have the same attribute value twice")
            Parent.list_of_unique_values_command_name.append(cls.command_name)
Child1
class ChildOne(Parent):
    command_name = "blabla"
    def __init__():
        print("hello1")
Child2
class ChildTwo(Parent):
    command_name = "blabla"
    def __init__():
        print("hello2")
This code works as expected when all classes are parsed by the Python interpreter. However, let's say the child classes are on different modules, and I run a command which only use one of them, Python won't detect that two child classes have the command_name attribute with the same value.
Is there any solution to fix this?
Edit1: I'm not searching for a solution such as a Singleton. The goal is that even if two child classes run in two different processes, they still can't have the same command_name attribute. (And it must be stateless)
 
     
    