[issue5377] Strange behavior when performing int on a Decimal made from -sys.maxint-1

Mark Dickinson report at bugs.python.org
Sat Mar 28 05:22:06 CET 2009


Mark Dickinson <dickinsm at gmail.com> added the comment:

Thanks for the patch, Victor.  I think this is the right thing to do, 
though I'm still not sure why anyone would care about getting longs 
instead of ints back from int(x).

Comments and questions:

(0) Please could you add some tests!
(1) Shouldn't the first line you added include a check for res == NULL?  
(2) It looks as though the patched code ends up calling PyLong_Check twice 
when __int__ returns a long.  Can you find a clear rewrite that avoids 
this duplication?

By the way, I realized after posting my last comment that the issue with 
Fraction has nothing to do with extreme int values.  For example, with the 
current trunk (not including Victor's patch):

>>> int(Fraction(2L))
2L
>>> int(int(Fraction(2L)))
2

I don't think should be considered a bug in Fraction---I think Victor's 
solution of making the int() machinery always return int when possible is 
the right one here.  The need to call int(int(x)) if you *really* want an 
int seems a little ugly.

----------
stage:  -> test needed

_______________________________________
Python tracker <report at bugs.python.org>
<http://bugs.python.org/issue5377>
_______________________________________


More information about the Python-bugs-list mailing list