[Python-ideas] Change Behind The Scenes Attribute Access from Class to Object

Nick Coghlan ncoghlan at gmail.com
Mon Dec 29 11:17:21 CET 2014

On 28 Dec 2014 06:17, "Adam Carruthers" <adam.j.carruthers at hotmail.co.uk>
> At the moment, when a python function, like print, calls an object
attribute it does this (if it were written in python):
>     type(obj).__str__(obj)
> This can be restrictive in lots of situations and I think it would be
better to just get the attribute from the object itself.
>     obj.__str__()

This is the way classic classes generally work in Python 2 (all classic
classes are handled by a single underlying type). Removing that behaviour
was one of the key changes in the new-style class model introduced in PEPs
252 and 253 (which is now the only class model in Python 3).

Delegating to a lookup on the instance at the type level is the appropriate
way to handle this when desired.


> It would make you free to override it on a per object basis. In some
cases, this could lead to huge optimization.
> Obviously, it is easy to fix yourself, but it is a layer of
uncharacteristic unintuitiveness:
>     def __str__(self):
>         self._str()
> _______________________________________________
> Python-ideas mailing list
> Python-ideas at python.org
> https://mail.python.org/mailman/listinfo/python-ideas
> Code of Conduct: http://python.org/psf/codeofconduct/
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/python-ideas/attachments/20141229/3467d188/attachment.html>

More information about the Python-ideas mailing list