[issue14462] In re's named group the name cannot contain unicode characters

New submission from py.user <port139@yandex.ru>: http://docs.python.org/py3k/library/re.html "(?P<name>...) Similar to regular parentheses, but the substring matched by the group is accessible within the rest of the regular expression via the symbolic group name name. Group names must be valid Python identifiers, and each group name must be defined only once within a regular expression."
chr(255) 'ÿ' 'ÿ'.isidentifier() True import re re.search(r'(?P<ÿ>a)', 'abc') Traceback (most recent call last): File "/usr/local/lib/python3.2/functools.py", line 176, in wrapper result = cache[key] KeyError: (<class 'str'>, '(?P<ÿ>a)', 0)
During handling of the above exception, another exception occurred: Traceback (most recent call last): File "<stdin>", line 1, in <module> File "/usr/local/lib/python3.2/re.py", line 158, in search return _compile(pattern, flags).search(string) File "/usr/local/lib/python3.2/re.py", line 255, in _compile return _compile_typed(type(pattern), pattern, flags) File "/usr/local/lib/python3.2/functools.py", line 180, in wrapper result = user_function(*args, **kwds) File "/usr/local/lib/python3.2/re.py", line 267, in _compile_typed return sre_compile.compile(pattern, flags) File "/usr/local/lib/python3.2/sre_compile.py", line 491, in compile p = sre_parse.parse(p, flags) File "/usr/local/lib/python3.2/sre_parse.py", line 692, in parse p = _parse_sub(source, pattern, 0) File "/usr/local/lib/python3.2/sre_parse.py", line 315, in _parse_sub itemsappend(_parse(source, state)) File "/usr/local/lib/python3.2/sre_parse.py", line 552, in _parse raise error("bad character in group name") sre_constants.error: bad character in group name
also: (?P=name) (?(name)yes|no) \g<name> ---------- assignee: docs@python components: Documentation, Regular Expressions messages: 157266 nosy: docs@python, ezio.melotti, mrabarnett, py.user priority: normal severity: normal status: open title: In re's named group the name cannot contain unicode characters type: behavior versions: Python 3.2 _______________________________________ Python tracker <report@bugs.python.org> <http://bugs.python.org/issue14462> _______________________________________

Ezio Melotti <ezio.melotti@gmail.com> added the comment: There are two options here: 1. fix the doc; 2. fix the code; Matthew, do you have any opinion on this? Does this work on regex? ---------- stage: -> needs patch type: behavior -> enhancement versions: +Python 2.7, Python 3.3 _______________________________________ Python tracker <report@bugs.python.org> <http://bugs.python.org/issue14462> _______________________________________

Matthew Barnett <python@mrabarnett.plus.com> added the comment: It doesn't work in regex, but it probably should. IMHO, if it's a valid identifier, then it should be allowed. ---------- _______________________________________ Python tracker <report@bugs.python.org> <http://bugs.python.org/issue14462> _______________________________________

Serhiy Storchaka added the comment: Here is a patch which make re to use for groups the same rule as for Python 3 identifiers. In Python 2 the implementation confirms the documentation. ---------- keywords: +patch nosy: +serhiy.storchaka stage: needs patch -> patch review versions: +Python 3.4 -Python 2.7 Added file: http://bugs.python.org/file28811/re_unicode_identifiers.patch _______________________________________ Python tracker <report@bugs.python.org> <http://bugs.python.org/issue14462> _______________________________________

Changes by Serhiy Storchaka <storchaka@gmail.com>: ---------- assignee: docs@python -> serhiy.storchaka _______________________________________ Python tracker <report@bugs.python.org> <http://bugs.python.org/issue14462> _______________________________________

Roundup Robot added the comment: New changeset 2fa27a3818a2 by Georg Brandl in branch '3.3': Closes #14462: allow any valid Python identifier in sre group names, as documented. http://hg.python.org/cpython/rev/2fa27a3818a2 ---------- nosy: +python-dev resolution: -> fixed stage: patch review -> committed/rejected status: open -> closed _______________________________________ Python tracker <report@bugs.python.org> <http://bugs.python.org/issue14462> _______________________________________
participants (5)
-
Ezio Melotti
-
Matthew Barnett
-
py.user
-
Roundup Robot
-
Serhiy Storchaka