Change Behind The Scenes Attribute Access from Class to Object
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__()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()
On 28 Dec 2014 06:17, "Adam Carruthers"
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. Cheers, Nick.
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@python.org https://mail.python.org/mailman/listinfo/python-ideas Code of Conduct: http://python.org/psf/codeofconduct/
participants (2)
-
Adam Carruthers
-
Nick Coghlan