Is this a bug in int()?

Duncan Booth duncan.booth at invalid.invalid
Thu Dec 20 16:56:31 EST 2007


MartinRinehart at gmail.com wrote under the subject line "Is this a 
bug in int()?":
>>>>int('0x', 16)
> 0
> 
I think it is a general problem in the tokenizer, not just the 'int' 
constructor. The syntax for integers says:

   hexinteger ::= "0" ("x" | "X") hexdigit+ 

but 0x appears to be accepted in source code as an integer.

If I were you, I'd try reporting it as a bug.

> I'm working on a tokenizer and I'm thinking about returning a
> MALFORMED_NUMBER token (1.2E, .5E+)
> 
Why would you return a token rather than throwing an exception?



More information about the Python-list mailing list