I was wandering how does elixir\sqlalchemy get to know all the entity classes I’ve declared in my model, when I call setup_all()? I need that kind of functionality in a little project of mine, but I have no clue. I’ve tried to steptrace through elixir’s setup_all(), and I found that it keeps a collection of all entity classes in a “global” list (or was it dict?), but I can’t catch the moment when the list is filled. Any ideas?
I was wandering how does elixir\sqlalchemy get to know all the entity classes I’ve
Share
Answering the main question, without dealign with SQLALchemy or elixir at all – yes, it is possible in Python.
The garbage colector (
gc) module on the standard library, have a function call that allows one to retrieve all references to a given object, interpreter wide. A class is always referred to in the__mro__attribute of any inherited classes.So, the following function could retrieve all classes that inherit from a given class: