[Python-ideas] Missing Core Feature: + - * / | & do not call __getattr__
Chris Angelico
rosuav at gmail.com
Fri Dec 4 09:12:48 EST 2015
On Sat, Dec 5, 2015 at 12:55 AM, Stephan Sahm <Stephan.Sahm at gmx.de> wrote:
> 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.
They might be, in the unusual case where the *instance* determines how
it reacts to an operator. In the far more common case where the *type*
determines it (that is, where all instances of a particular type
behave the same way), the current system has less overhead. (Though
I'm not sure how much less, nor even if it's been measured.)
If you really do need this kind of per-object dynamism, you still
probably don't actually need it for _every_ operator, so you can
simply create a bouncer for each dunder method that you actually need
this dynamic dispatch on, and as you say, toss them into a mixin if
necessary.
ChrisA
More information about the Python-ideas
mailing list