__iadd__ useless in sub-classed int

Neil Cerutti horpner at yahoo.com
Thu Dec 6 16:17:57 EST 2007


On 2007-12-06, samwyse <samwyse at gmail.com> wrote:
> And that's my complaint.  The value in <zed> is being replaced
> by something almost, but not quite, identical to the original
> value. Python's internal implementation of __iadd__ for <int>
> isn't returning <self>, it's returning a new value belonging to
> the super-class.

int.__iadd__ cannot return self because int instances are
immutable. In order to return self it would first have to change
what's unchangeable.

> My whole point is overloading <int> was that
> I'd hoped to avoid having to write a bunch of methods to
> perform in-place modifications.  Looks like I stuck, however.

You have to implement only the operations you actually use. So to
save yourself drudge-work, use fewer operations. ;-)

-- 
Neil Cerutti



More information about the Python-list mailing list