[Python-ideas] Missing Core Feature: + - * / | & do not call __getattr__
Nick Coghlan
ncoghlan at gmail.com
Fri Dec 4 09:14:17 EST 2015
On 4 December 2015 at 23:55, Stephan Sahm <Stephan.Sahm at gmx.de> wrote:
> Thanks for the constructive response!
>
> this is good to know, however it still forces me make such a dynamic
> placeholder explicit for every single operator.
> Still, I could put everything in a Mixin class so that it is in fact useful
> to clean up code.
>
> However, in the long run, such placeholders seem like an unnecessary
> overhead to me.
The current behaviour is by design - special methods are looked up as
slots on the object's class, not as instance attributes. This allows
the interpreter to bypass several steps in the normal instance
attribute lookup process.
> I myself thought whether one can insert the methods into the class itself
> using __new__ or something else concerning meta-classes. My background is
> however not good enough in order to seriously explore this direction.
>
> Any further suggestions?
Graham Dumpleton's wrapt module has a robust implementation of object
proxies: http://wrapt.readthedocs.org/en/latest/wrappers.html
Even if that library isn't directly applicable to your use case,
studying the implementation should be informative.
Cheers,
Nick.
--
Nick Coghlan | ncoghlan at gmail.com | Brisbane, Australia
More information about the Python-ideas
mailing list