[issue10581] Review and document string format accepted in numeric data type constructors

Alexander Belopolsky report at bugs.python.org
Mon Jun 17 02:56:47 CEST 2013


Alexander Belopolsky added the comment:

I took another look at the library reference and it looks like when it comes to non-ascii digits support, the reference contradicts itself.  On one hand,

"""
int(x, base=10)

If x is not a number or if base is given, then x must be a string, bytes, or bytearray instance representing an integer literal in radix base. Optionally, the literal can be preceded by + or - (with no space in between) and surrounded by whitespace.
""" <http://docs.python.org/3/library/functions.html#int>

.. suggests that only "an integer literal" will be accepted by int(), but on the other hand, a note in the "Numeric Types" section says: "The numeric literals accepted include the digits 0 to 9 or any Unicode equivalent (code points with the Nd property)." <http://docs.python.org/3/library/stdtypes.html#typesnumeric>

It also appears that "surrounded by whitespace" part is not entirely correct:

>>> '\N{RS}'.isspace()
True
>>> int('123\N{RS}')
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
ValueError: invalid literal for int() with base 10: '123\x1e'

This is probably a bug in the current implementation and I will open a separate issue for that.

----------
versions: +Python 3.4

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


More information about the Python-bugs-list mailing list