[Python-ideas] Missing Core Feature: + - * / | & do not call __getattr__
Stephan Sahm
Stephan.Sahm at gmx.de
Fri Dec 4 09:22:21 EST 2015
thank you two
the wrapt link is on my future todo-list, will need some more time than I
currently have
You both mentioned that the operators might be better tackleable via
class-interfaces (__slots__ e.g.?)
How would it look like to change things on this level?
My current usecase is to implement a Mixin abc class which shall combine
all the available __iadd__ __ior__ and so on with a copy() function (this
one is then the abstractmethod) to produce automatically the respective
__add__, __or__ and so on
On 4 December 2015 at 15:14, Nick Coghlan <ncoghlan at gmail.com> wrote:
> 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
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/python-ideas/attachments/20151204/5fa6a522/attachment.html>
More information about the Python-ideas
mailing list