[issue40980] group names of bytes regexes are strings

Ma Lin report at bugs.python.org
Tue Jun 16 06:30:47 EDT 2020


Ma Lin <malincns at 163.com> added the comment:

> a non-ascii group name will raise an error in bytes, even if encoded

Looks like this is a language limitation:

    >>> b'é'
      File "<stdin>", line 1
    SyntaxError: bytes can only contain ASCII literal characters.

No problem if you use escaped character:

    >>> re.match(b'(?P<\xe9>)', b'').groupdict()
    {'é': b''}

There may be some inconveniences in your program, but IMO there is nothing wrong, maybe this issue can be closed.

----------

_______________________________________
Python tracker <report at bugs.python.org>
<https://bugs.python.org/issue40980>
_______________________________________


More information about the Python-bugs-list mailing list