Skip to content

re.findall specific types str | bytes - #16074

Merged
srittau merged 2 commits into
python:mainfrom
relikd:main
Jul 22, 2026
Merged

re.findall specific types str | bytes#16074
srittau merged 2 commits into
python:mainfrom
relikd:main

Conversation

@relikd

@relikd relikd commented Jul 22, 2026

Copy link
Copy Markdown
Contributor

I hope I am not missing something important, but shouldn't these types be specific?

@github-actions

This comment has been minimized.

Comment thread stdlib/re.pyi Outdated
@@ -171,9 +171,9 @@ class Pattern(Generic[AnyStr]):

# return type depends on the number of groups in the pattern

@srittau srittau Jul 22, 2026

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The problem is that findall returns either a list[X] or a list[tuple[X, ...]] where X is either str or bytes, depending on the pattern. Since unions in return types are problematic in cases like this (see also python/typing#566 for a possible solution), list[Any] is the best we can do.

That said, I think we could improve this comment to make this more clear:

Suggested change
# return type depends on the number of groups in the pattern
# return type is either list[str/bytes] or list[tuple[str/bytes, ...]]
# depending on the number of groups in the pattern

We also should copy this comment to the other findall group below.

@relikd relikd Jul 22, 2026

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

thank you, I removed my suggested change and added the comments

@github-actions

Copy link
Copy Markdown
Contributor

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

@srittau
srittau merged commit 071be77 into python:main Jul 22, 2026
73 checks passed
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