You are right: long(4.2) used to return a long.
This was changed by the introduction of the float_trunc() function,
which is now used for float.__trunc__, float.__int__ and float.__long__.
OTOH, long() has always been allowed to return an int. Checked with
python2.2:
>>> class C:
... def __long__(self): return 4
...
>>> type(long(C()))
<type 'int'>
I suggest that:
- your code should be more tolerant, specially when calling API
functions from the "Abstract Objects Layer", accept both longs and ints.
- Concerning long(float()), the new behavior breaks existing code, and
should be reverted. I will try to come with a patch. |