[Python-Dev] Dinamically set __call__ method

Ian Kelly ian.g.kelly at gmail.com
Tue Nov 11 08:43:40 CET 2014

On Sat, Nov 8, 2014 at 3:31 PM, Gregory Ewing
<greg.ewing at canterbury.ac.nz> wrote:
> (BTW, I'm actually surprised that this technique makes c callable.
> There must be more going on that just "look up __call__ in the class
> object", because evaluating C.__call__ just returns the descriptor
> and doesn't invoking the descriptor mechanism.)

But of course it doesn't just lookup C.__call__, because it has to
bind the method to the instance before calling it, which means
invoking the descriptor protocol. The actual lookup is more like:

type(a).__dict__['__call__'].__get__(a, type(a))

More information about the Python-list mailing list