__iadd__ useless in sub-classed int

A.T.Hofkamp hat at se-162.se.wtb.tue.nl
Mon Dec 10 06:46:39 EST 2007


On 2007-12-06, samwyse <samwyse at gmail.com> wrote:
> On Dec 6, 1:12 pm, "Diez B. Roggisch" <de... at nospam.web.de> 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.  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.

I think you don't want this.

Suppose I keep track of addition information (eg a boolean "is_even = value ==
value//2") Since the base class doesn't know about this, it may return an
incorrect instance.

Albert




More information about the Python-list mailing list