Skip to content

wrong annotation for typing.Match.groups() #4380

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
arnimarj opened this issue Jul 31, 2020 · 1 comment
Closed

wrong annotation for typing.Match.groups() #4380

arnimarj opened this issue Jul 31, 2020 · 1 comment

Comments

@arnimarj
Copy link
Contributor

arnimarj commented Jul 31, 2020

Hi,

Just noticed that the annotation for typing.Match.groups() seems to be wrong. It's currently at ... -> Sequence[AnyStr]: ..., but I believe it should be ... -> Sequence[Optional[AnyStr]]: .... This documentation seems to agree: https://docs.python.org/3/library/re.html#re.Match.groups

import re

def matchalot(s: str) -> None:
	print('string', s)

	pattern = re.compile('^([1-9]a)([1-9]b)?([1-9]c)?$')
	search = pattern.search(s)
	assert(search)

	print('groups', search.groups())
	print('------------')


matchalot('3a')
matchalot('3a2b')
matchalot('3a1c')
matchalot('3a2b1c')

outputs this on Python 3.8:

string 3a
groups ('3a', None, None)
------------
string 3a2b
groups ('3a', '2b', None)
------------
string 3a1c
groups ('3a', None, '1c')
------------
string 3a2b1c
groups ('3a', '2b', '1c')
------------

Fix candidate here: #4381

arnimarj added a commit to arnimarj/typeshed that referenced this issue Jul 31, 2020
@srittau
Copy link
Collaborator

srittau commented Jul 31, 2020

Closing as duplicate of #3902. Please see there for some prior discussion. Unfortunately, it's not that easy to solve.

@srittau srittau closed this as completed Jul 31, 2020
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 a pull request may close this issue.

2 participants