[Python-Dev] Dinamically set __call__ method

Ethan Furman ethan at stoneleaf.us
Tue Nov 4 20:12:15 CET 2014

On 11/04/2014 11:01 AM, Roberto Martínez wrote:
> Yikes, I didn't realize the difference in inheritance.
> The thing with this is tricky. I need the change in the instance, not in the class, because I have multiple instances
> and all of them must have different implementations of __call__.
> The workaround of calling a different method inside __call__ is not valid for my case because I want to change the
> *signature* of the function also -for introspection reasons.

If you really absolutely positively have to have the signature be correct for each instance, you may to either look at a 
function creating factory, a class creating factory, or a meta-class.  The first option may work if you don't need an 
actual class, both of the last two options will be creating different classes, probably with one instance each (unless 
you have several instances which could share the same __call__).


More information about the Python-list mailing list