Commit ed4536df authored by Kevin Modzelewski's avatar Kevin Modzelewski

Unfortunately int.__new__(cls) does not always return an instance of cls

If cls is int, and the argument has an __int__ method that returns
a subclass of int (that is not an int), then int.__new__ will return
that.

Will need to make the typeCall rewriting criteria tighter.
parent 8aa6259f
......@@ -18,7 +18,8 @@ print -1 ** 0
# Testing int.__new__:
class C(int):
pass
def __init__(self, *args):
print "C.__init__, %d args" % len(args)
class D(object):
def __init__(self, n):
......@@ -35,3 +36,12 @@ try:
int.__new__(C, D(1.0))
except TypeError, e:
print e
class I(int):
pass
x = int(D(C()))
print type(x)
x = I(D(C()))
print type(x)
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment