[Python-Dev] Dinamically set __call__ method

Fabio Zadrozny fabiofz at gmail.com
Thu Nov 13 14:38:57 CET 2014

On Thu, Nov 13, 2014 at 2:20 AM, Gregory Ewing <greg.ewing at canterbury.ac.nz>

> Fabio Zadrozny wrote:
>> can someone from python-dev give some background of why that's the way it
>> is?
> It's because, with new-style classes, a class is also an
> instance (of class "type" or a subclass thereof). So
> without that rule, it would be ambiguous whether a dunder
> method applied to instances of a class or to the class
> itself.
> > 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
> Something fairly fundamental that would break is classs
> instantiation! You instantiate a class by calling it, so if
> a(x) were implemented as a.__call__(x), and class C had
> a __call__ method, then C() would invoke that method
> instead of instantiating C.
Hi Gregory,

Thanks for the explanation -- it still does seem a bit surprising from an
end-user point of view, but it does make more sense now :)

Best Regards,

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/python-list/attachments/20141113/623f3d9f/attachment.html>

More information about the Python-list mailing list