Actually int("3.14") does not round. int(3.14) does. 

On Friday, 11 October 2013 20:43:54 UTC-5, Massimo Di Pierro wrote:
>
> I am adding the +- but we cannot use int because int("3.14") would round.
>
> Anyway, I agree this can be rewritten better. Feel free to post your patch 
> on google code or as a github pull request. Thanks.
>
> Massimo
>
> On Friday, 11 October 2013 20:05:29 UTC-5, Stefan Pochmann wrote:
>>
>> It's better, but...
>>
>> Outside character classes, the "-" is not a metacharacter and thus 
>> doesn't need a backslash. So it could/should be:
>> re.compile('^-?\d+$')
>>
>> You might want to accept a plus sign like in "+43" (Python's int(...) 
>> does accept it), so:
>> re.compile('^[-+]?\d+$')
>>
>> Or don't reinvent Python's existint int(...) with an ugly regex way but 
>> use Python's common "Easier to ask for forgiveness than permission" style, 
>> maybe like this:
>>
>>     def __call__(self, value):
>>         try:
>>             v = int(value)
>>             if ((self.minimum is None or v >= self.minimum) and
>>                 (self.maximum is None or v < self.maximum)):
>>                 return (v, None)
>>         except:
>>             pass
>>         return (value, self.error_message)
>>
>> You also changed the default to IS_INT_IN_RANGE(-2**31, 2**31-1), but I 
>> think it shouldn't have that "-1" because "The range is interpreted in the 
>> Pythonic way, so the test is: min <= value < max".
>>
>> I also find __init__ quite complicated and have a rewrite suggestion. 
>> Should I post it here or try a pull request or...?
>>
>

-- 
Resources:
- http://web2py.com
- http://web2py.com/book (Documentation)
- http://github.com/web2py/web2py (Source code)
- https://code.google.com/p/web2py/issues/list (Report Issues)
--- 
You received this message because you are subscribed to the Google Groups 
"web2py-users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to web2py+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.

Reply via email to