[Python-Dev] Dinamically set __call__ method
fabiofz at gmail.com
Wed Nov 12 16:33:57 CET 2014
On Tue, Nov 11, 2014 at 5:43 AM, Ian Kelly <ian.g.kelly at gmail.com> wrote:
> 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))
As a reference, I recently found a blog post related to that:
Slots part comments on that).
It does seem a bit counter-intuitive that this happens the way it does
though, so, can someone from python-dev give some background of why that's
the way it is? i.e.: instead of the approach which would seem simpler which
would do getattr(a, '__call__') instead of
type(a).__dict__['__call__'].__get__(a, type(a)) -- it seems to me it's
mostly because of historical reasons, but I'm really curious why is it so
(and if maybe it's something which python-dev would consider worth changing
in the future -- not sure how much could break because of that though).
Thanks and Best Regards,
-------------- next part --------------
An HTML attachment was scrubbed...
More information about the Python-list