<p dir="ltr"><br>
On 28 Dec 2014 06:17, "Adam Carruthers" <<a href="mailto:adam.j.carruthers@hotmail.co.uk">adam.j.carruthers@hotmail.co.uk</a>> wrote:<br>
><br>
> At the moment, when a python function, like print, calls an object attribute it does this (if it were written in python):<br>
>     type(obj).__str__(obj)<br>
> This can be restrictive in lots of situations and I think it would be better to just get the attribute from the object itself.<br>
>     obj.__str__()</p>
<p dir="ltr">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).</p>
<p dir="ltr">Delegating to a lookup on the instance at the type level is the appropriate way to handle this when desired.</p>
<p dir="ltr">Cheers,<br>
Nick.<br></p>
<p dir="ltr">> It would make you free to override it on a per object basis. In some cases, this could lead to huge optimization.<br>
> Obviously, it is easy to fix yourself, but it is a layer of uncharacteristic unintuitiveness:<br>
>     def __str__(self):<br>
>         self._str()<br>
><br>
> _______________________________________________<br>
> Python-ideas mailing list<br>
> <a href="mailto:Python-ideas@python.org">Python-ideas@python.org</a><br>
> <a href="https://mail.python.org/mailman/listinfo/python-ideas">https://mail.python.org/mailman/listinfo/python-ideas</a><br>
> Code of Conduct: <a href="http://python.org/psf/codeofconduct/">http://python.org/psf/codeofconduct/</a><br>
</p>