__iadd__ useless in sub-classed int

samwyse samwyse at gmail.com
Thu Dec 6 14:03:49 EST 2007


For whatever reason, I need an inproved integer.  Sounds easy, let's
just subclass int:

>>> class test(int):
	pass

Now let's test it:

>>> zed=test(0)
>>> zed.__class__
<class '__main__.test'>
>>> zed
0

So far, so good.  Now let's try incrementing:

>>> zed+=1
>>> zed
1
>>> zed.__class__
<type 'int'>

WTF??!
Is this a bug or is it the inevitable result of optimizing for the
case where all integers are indistinguishable?



More information about the Python-list mailing list