__iadd__ useless in sub-classed int

MonkeeSage MonkeeSage at gmail.com
Fri Dec 7 03:37:11 EST 2007


On Dec 7, 12:45 am, "Gabriel Genellina" <gagsl-... at yahoo.com.ar>
wrote:
> En Fri, 07 Dec 2007 03:01:28 -0300, MonkeeSage <MonkeeS... at gmail.com>
> escribió:
>
> > I've wondered about this myself. Seems to me, to prevent clobbering
> > subclasses, __iadd__ (and all of the integer and float and whatever)
> > methods that return new instances, should work like this (obviously I
> > mean in the C backend, this is just to show the behavior):
>
> > def __iadd__(self, other):
> >   return self.__class__(self + other)
>
> This would slow down *all* of Python, and is only useful for those who
> actually inherit from some builtin class (not so common)
>
> --
> Gabriel Genellina

I understand why it doesn't. It just *seems* like it should work that
way when you first run into it (and has bitten me a couple times
before). But then, I'm not Dutch. :)

Regard,
Jordan



More information about the Python-list mailing list