[New-bugs-announce] [issue12538] Extending int class

João Bernardo report at bugs.python.org
Mon Jul 11 22:26:03 CEST 2011

New submission from João Bernardo <jbvsmo at gmail.com>:

I'm having trouble subclassing the int type and I think this behavior is a bug... (Python 3.2)

>>> class One(int):
	def __init__(self):

>>> one = One()
>>> one + 2
>>> one == 0

I know `int` objects are immutable but my `One` class should be mutable... and why it doesn't raise an error?

That gives the same result on Python 2.7 using super properly.

Also, if that's not a bug, how it should be done to achieve "one + 2 == 3" without creating another attribute.

Things I also tried:
    self.real = 1  #readonly attribute error
    int.__init__(self, 1)  #same behavior

I Couldn't find any related issues... sorry if it's repeated.

components: Interpreter Core
messages: 140161
nosy: JBernardo
priority: normal
severity: normal
status: open
title: Extending int class
type: behavior
versions: Python 2.7, Python 3.2

Python tracker <report at bugs.python.org>

More information about the New-bugs-announce mailing list