[Python-Dev] Dinamically set __call__ method

Roberto Martínez robertomartinezp at gmail.com
Tue Nov 4 14:15:24 EST 2014


On Tue, Nov 4, 2014 at 8:06 PM, Skip Montanaro <skip.montanaro at gmail.com>
wrote:

>
> On Tue, Nov 4, 2014 at 1:01 PM, Roberto Martínez <
> robertomartinezp at gmail.com> wrote:
>
>> 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.
>
>
> You could define __call__ like so:
>
> def __call__(self, *args, **kwds):
>     self._my_call(*args, **kwds)
>

This was my first approach, but it is not very informative to the user and
I prefer to have arguments with descriptive names. We have to change
__doc__ too, so this is not an ideal solution for me.

I tried to implement __getattribute__, but is not called either. :(

then set self._my_call at runtime.
>
> Skip
>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/python-list/attachments/20141104/2f6549a1/attachment.html>


More information about the Python-list mailing list