Strange behaviour: subclass of int returns 3 when constructed with long

Anton Muhin antonmuhin at sendmail.ru
Sun Feb 9 10:12:47 EST 2003


Gerrit Holl wrote:
> Hi,
> 
>   0 >>> class A(int): pass
>   0 ...
>   1 >>> int(sys.maxint)
> 2147483647
>   2 >>> A(sys.maxint)
> 2147483647
>   3 >>> int(sys.maxint+1)
> 2147483648L
>   4 >>> A(sys.maxint+1)
> 3
>   5 >>> A(sys.maxint+42)
> 3
>   6 >>> int(A(sys.maxint+1))
> 3
> 
> how can this behaviour be explained? Shouldn't A behave identical to int?
> 
> yours,
> Gerrit.
> 

My ActiveState Python 2.2 on Windows XP in PythonWin reports:

 >>> a0 = A(sys.maxint + 1); print a0
Traceback (most recent call last):
   File "<interactive input>", line 1, in ?
OverflowError: long int too large to convert to int
 >>> a0 = A(sys.maxint + 42); print a0
Traceback (most recent call last):
   File "<interactive input>", line 1, in ?
OverflowError: long int too large to convert to int
 >>>

Anton.





More information about the Python-list mailing list