[New-bugs-announce] [issue17331] Fix str methods for detecting digits with unicode

Mathieu Pasquet report at bugs.python.org
Fri Mar 1 21:53:40 CET 2013


New submission from Mathieu Pasquet:

In py3k, str.isalnum(), str.isdigit(), and str.isdecimal() are broken because they take into account various unicode numbers.

A common case is doing something like that:

num = -1
while num == -1:
    num_in = input('Enter a number> ')
    if num_in.isdigit():
        num = int(num_in)

# do stuff …

If you enter ¹, or any esoteric unicode representation of a number, all the methods referenced above will return True. I believe this is a bug.

It also affects the stdlib, e.g. in collection.namedtuple,
A = namedtuple('A¹', 'x y') will return an ugly Syntax Error, because the sanity check uses str.isalnum(), which says it’s ok. (n.b.: of course, no sane person should ever want to do the above, but I find it worth mentionning)

----------
components: Unicode
messages: 183291
nosy: ezio.melotti, mathieui
priority: normal
severity: normal
status: open
title: Fix str methods for detecting digits with unicode
type: behavior
versions: Python 3.3

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


More information about the New-bugs-announce mailing list