Register classes in different files to a Class factory

Viewed 16

I am trying to register classes that are in different files to the factory class. The factory class has a dictionary called "registry" which hold/maps the a user defined name to the registering class. My issue is that if my factory class and registering classes are in the same .py file everything works as expected but the moment I move the registering classes into their own .py files and import the factory class to apply the register decorator (as described in the question & article below) the "registry" dictionary stays empty, which means that the classes are not getting registered.

They way I am registering these classes is via a decorator. My code looks very much like what we see here:

I would like to know:

  • What why keeping them in the same file work while splitting them out doest
  • How can I make the separate file approach work ?

Hopefully the code samples in the articles clarify what I am trying to do and struggling with.

0 Answers
Related