I have a class hierarchy that I want to register so I can later access it. So far I've been doing it manually:
class FirstClass(MyBaseClass):
....
registry.register(FirstClass)
class SecondClass(FirstClass):
....
registry.register(SecondClass)
I'm looking for a way to call registry.register(Class)
when the class is evaluated (that is, when someone imports the package with the class), without having to call it explicitly.
I guess I have to add something to MyBaseClass
, but I couldn't figure out what. All the special methods seem to be instance related, not class related.
Is there a way to do that?
Explanation: Registry keeps track of the classes derived from BaseClass. At some point in the code, I go over all these classes and instantiate objects. It is a bit more complicated than that, as registry is doing other things as well, but that's the main idea.