[Python-Dev] [2.3a2+] Change in int() behavior
Tim Peters
tim.one@comcast.net
Fri, 07 Mar 2003 23:06:53 -0500
[David Abrahams]
> The following change in behavior is causing one of my tests to fail.
Dear Lord, another buggy test <wink>.
> Is it intentional?
Yes, as part of the ongoing push toward int/long unification. If you tried
the same test in Python 2.1, it would have blown up in the "sys.maxint * 2"
part. In 2.2, it blows up in the "int()" part. In 2.3, it doesn't blow up
at all. In 2.4 or 2.5, __builtin__.int and __builtin__.long may well be the
same object.
> Should isinstance(int(x),int) really ever return False?
In 2.3, yes (albeit unfortunately).
> Python 2.2.2 (#1, Feb 3 2003, 14:10:37)
> >>> int(sys.maxint * 2)
> Traceback (most recent call last):
> File "<stdin>", line 1, in ?
> OverflowError: long int too large to convert to int
> Python 2.3a2+ (#1, Feb 24 2003, 15:02:10)
> >>> int(sys.maxint * 2)
> 4294967294L
Adding one more:
Python 2.1.3 (#35, Apr 8 2002, 17:47:50) [MSC 32 bit (Intel)] on win32
>>> int(sys.maxint * 2)
Traceback (most recent call last):
File "<stdin>", line 1, in ?
OverflowError: integer multiplication