Skip to content

Python2: fix groupindex and lastgroup for re #6778

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 1 commit into from

Conversation

jpy-git
Copy link
Contributor

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

Follow up PR to #6776.

I checked these types for Python 2.7 as well and observed the same behaviour:

>>> import re
>>> re.compile(r"(?P<test>\w)").groupindex
{'test': 1}
>>> re.compile(b"(?P<test>\w)").groupindex
{'test': 1}
>>> re.compile(r"(?P<test>\w)").search("a1").lastgroup
'test'
>>> re.compile(b"(?P<test>\w)").search(b"a1").lastgroup
'test'

N.B. I also checked if #6763 also applies to Python 2 and observed that Nones are not produced so the current Python 2 typing for re.Pattern.split() is correct.

@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. 🤖🎉

@Akuli
Copy link
Collaborator

Akuli commented Jan 1, 2022

All of your tests use the same kind of string. In Python 2, type("") is type(b"").

What's your motivation for fixing anything in the Python 2 stubs? We will accept pull requests, but at least I personally don't really care about whether anyone fixes them.

@jpy-git jpy-git closed this Jan 1, 2022
@jpy-git jpy-git deleted the py2_re_groupindex_lastgroup branch January 1, 2022 21:13
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.

2 participants