[fastcore, nbdev] Dispatching for multiple types

Hey there!
Although I was actually not a fan of notebook development from the beginning, I am now totally hooked. It’s really awesome, working on all aspects of a package (code, docs, tests) was never so integrated. Totally love it.

I’m kind of exploring what you can do with nbdev and fastcore at the moment and I’d like to have feedback on something I tried. I wanted to make a class MultiImage that can take all of Union[torch.tensor, np.array, PIL.Image.Image]. Now when I’m implementing a method for this class I want to create a specific one for each type and dispatch the correct one during runtime, so that a user only sees the generic method. Also I want to use monkey patching to be able to split the class for documentation purposes and to add functionality later on.

Here’s what I tried:

The only thing I still don’t like is that you have to specify all (same) parameters several times when implementing each method.

Thanks for feedback!

EDIT: I now automated the dispatching and a generic not_implemented function if a method for a type is not implemented.