Skip to content

Conversation

@jpy-git
Copy link
Contributor

@jpy-git jpy-git commented Jan 1, 2022

Another tweak to re that I spotted when working through the regex stubs.

re.Match.lastgroup is derived from indexgroup (inverse of groupindex) and therefore must be a str:
https://github.com/python/cpython/blob/0b58bac3e7877d722bdbd3c38913dba2cb212f13/Modules/_sre.c#L2375-L2388

Group names are always stored as strings, even if the pattern and string are bytes:

>>> import re
>>> re.compile(b"(?P<letter>\w)").match(b"a1").lastgroup
'letter'

@github-actions
Copy link
Contributor

github-actions bot commented Jan 1, 2022

According to mypy_primer, this change has no effect on the checked open source code. 🤖🎉

@AlexWaygood
Copy link
Member

Good catch!!

@Akuli Akuli merged commit d43cd99 into python:master Jan 1, 2022
@jpy-git jpy-git deleted the re_groupindex branch January 1, 2022 13:15
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants