jeudi 11 octobre 2018

How to get some attribute from a class generated by a metaclass

I have a metaclass in python that generates a few classes with an attribute called _collections.

From the metaclass, I want to check all the _collections attributes in the classes, but when I try it out, I get None because the classes are not generated when I query them in the metaclass.

Is there any way to work around that?

task_subclasses = cls._subclasses
   for task_subclass in task_subclasses:
       print(getattr(sys.modules[Task.__module__], task_subclass)()._collection)

It prints None but when I import the Task module all collections are instantiated.





Aucun commentaire:

Enregistrer un commentaire