I'm wanting to keep a class attribute on a base class which keeps track of all names of all its subclasses.
class SomeThing(abc.ABC):
   subclass_names = set()
   def __init_subclass__(cls):
       cls.subclass_names.add(cls.__name__)
       print(cls.subclass_names)
However, I'm afraid that because I'm creating an abstract class, users might overwrite the class attribute I am keeping.
class SomeSub(SomeThing):
    subclass_names = set()
out: {'SomeSub'}
class SomeOtherSub(SomeThing):
    pass
out: {'SomeOtherThing'} # should be {'SomeSub', 'SomeOtherThing'}
# but SomeOtherThing is registered in SomeOtherThing's, not SomeThing's subclass_names
Is there a way to refer to "own class" in a class method? It seems like the cls in __init_subclass__ ends up being whichever subclass is passed in (which makes sense).



SomeThing.__subclasses__()SomeThing.subclass_names.__subclasses__only returns direct subclasses, not all subclasses of subclasses, recursively.)