Re: Possible bug with Number validator

Christoph Zwerschke <[email protected]> Thu, 09 Apr 2009 19:35:24 +0200
Newsgroups gmane.comp.python.formencode
Message-ID <[email protected]>
Aston Motes schrieb:
 > int(float('inf')) raises an OverflowException. The problematic lines
 > are something like
 >
 >     value = float(value)
 >     if value == int(value):

That has been fixed already 6 months ago in r3657 by catching the 
possible OverflowError here:

             value = float(value)
             try:
                 int_value = int(value)
             except OverflowError:
                 int_value = None
             if value == int_value:
                 return int_value
             return value

However, I think this comparison also does not work when you have really 
huge values like 1e30 where you will get the following:

 >>> print Number().to_python(1e33)
999999999999999945575230987042816

This is probably not what we want. Maybe the following is better:

if value == int_value and '%.f' % value == str(int_value):
     return int_value

-- Christoph

------------------------------------------------------------------------------
This SF.net email is sponsored by:
High Quality Requirements in a Collaborative Environment.
Download a free trial of Rational Requirements Composer Now!
http://p.sf.net/sfu/www-ibm-com