[New-bugs-announce] [issue40980] group names of bytes regexes are strings

Quentin Wenger report at bugs.python.org
Sun Jun 14 17:03:34 EDT 2020


New submission from Quentin Wenger <wenger.quentin at bluewin.ch>:

I noticed that match.groupdict() returns string keys, even for a bytes regex:

```
>>> import re
>>> re.match(b"(?P<a>)", b"").groupdict()
{'a': b''}
```

This seems somewhat strange, because string and bytes matching in re are kind of two separate parts, cf. doc:

> Both patterns and strings to be searched can be Unicode strings (str) as well as 8-bit strings (bytes). However, Unicode strings and 8-bit strings cannot be mixed: that is, you cannot match a Unicode string with a byte pattern or vice-versa; similarly, when asking for a substitution, the replacement string must be of the same type as both the pattern and the search string.

----------
components: Regular Expressions
messages: 371516
nosy: ezio.melotti, matpi, mrabarnett
priority: normal
severity: normal
status: open
title: group names of bytes regexes are strings
type: behavior
versions: Python 3.8

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


More information about the New-bugs-announce mailing list