Skip to content

re match objects fail validation when using string as argument to group #3199

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
posita opened this issue Apr 19, 2017 · 2 comments
Closed

Comments

@posita
Copy link
Contributor

posita commented Apr 19, 2017

This is probably a special case of #1141, but this usage is explicitly documented in the standard library. From the docs for re match objects for both version 2 and version 3 (emphasis added):

If the regular expression uses the (?P<name>...) syntax, the groupN arguments may also be strings identifying groups by their group name.

# re_match_group.py
from __future__ import print_function
import re
m = re.search(r'^(?P<foo>bar)$', u'bar')
ms = m.group(u'foo')
print(ms)

Result fails in 2 …

$ mypy --version
mypy 0.501
$ python2.7 re_match_group.py
bar
$ mypy -2 re_match_group.py
re_match_group.py:5: error: No overload variant of "group" of "Match" matches argument types [builtins.unicode]

… and 3 …

$ python3.6 re_match_group.py
bar
$ mypy re_match_group.py
re_match_group.py:5: error: No overload variant of "group" of "Match" matches argument types [builtins.unicode]
@gvanrossum
Copy link
Member

Can you file that in typeshed instead?

@posita
Copy link
Contributor Author

posita commented Apr 19, 2017

Ah! Sorry. I knew better. 😞 It's already filed: python/typeshed#273. Apologies!

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

No branches or pull requests

2 participants