Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

re.Match.lastgroup is str rather than AnyStr#6776

Merged
Akuli merged 1 commit into
python:masterpython/typeshed:masterfrom
jpy-git:re_groupindexjpy-git/typeshed:re_groupindexCopy head branch name to clipboard
Jan 1, 2022
Merged

re.Match.lastgroup is str rather than AnyStr#6776
Akuli merged 1 commit into
python:masterpython/typeshed:masterfrom
jpy-git:re_groupindexjpy-git/typeshed:re_groupindexCopy head branch name to clipboard

Conversation

@jpy-git

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

Copy link
Copy Markdown
Contributor

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

github-actions Bot commented Jan 1, 2022

Copy link
Copy Markdown
Contributor

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

@AlexWaygood

Copy link
Copy Markdown
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

Morty Proxy This is a proxified and sanitized view of the page, visit original site.