Closed Jaymon closed 5 months ago
Turns out this is a bit more complicated than I originally expected. I need to update both the internal dispatch but also the getattribute dispatch (_parse_method_name
), this is how I'm thinking to solve it:
_dispatch_method
to work through the mro and checking each method name generated using the parent class model_name
against the actual methods in the class using set(dir(self))
_parse_method_name
into a supporting method that parses model_name
from the method namedatatypes.ReflectSubClasses
to return the mro for a given class and using it's internal cutoff classes, this was done in https://github.com/Jaymon/datatypes/commit/f553819be9261b06e58ac92244367e5f11341587model.Orms
to return the set of model names for class and all its parents using the new reflect sub classes's mro functionality__getattribute__
can use to get the actual method and the orm class, I have to be careful here because calling internal methods causes __getattribute__
to be called again and can easily lead to infinite recursion.
Let's say I had something like this:
Now, I create a custom testdata method:
Now, what happens when I call this from my test method?
It resolves the methods like this:
But I would like it to resolve the method like this:
This should actually be pretty easy to do, I just need to modify
prom.extras.testdata.ModelData._dispatch_method
to grab all the parents and check them also before falling back to the passed in default method.