Preserve groupby iterator alternatives for union inputs#16019
Open
JSap0914 wants to merge 1 commit into
Open
Conversation
Contributor
|
According to mypy_primer, this change has no effect on the checked open source code. 🤖🎉 |
| @overload | ||
| def __iter__(self) -> Iterator[_T_co]: ... | ||
| @overload | ||
| def __iter__(self) -> _IteratorT_co: ... # type: ignore[overload-cannot-match] |
Collaborator
There was a problem hiding this comment.
this doesn't make sense to me
hauntsaninja
left a comment
Collaborator
There was a problem hiding this comment.
i'm not sure i understand this, and i'm not sure how intentional it is that this works for ty. it also might be unsound for elements that compare equal to other types
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
What
Model the no-key
itertools.groupbyoverload with the input's concrete iterator type, while retaining the existing publicgroupby[key, item]annotation shape.Why
For a union such as
Sequence[str] | Sequence[int], each produced group is homogeneous at runtime. Preserving the input iterator alternatives prevents the groups from being widened toIterator[str | int].Fixes #16018
Tests
PATH="$PWD/.venv/bin:$PATH" .venv/bin/pre-commit run --files stdlib/itertools.pyi stdlib/@tests/test_cases/itertools/check_groupby.pyPATH="$PWD/.venv/bin:$PATH" .venv/bin/python tests/ty_test.py stdlib/itertools.pyi --python=.venv/bin/python --python-version=3.13 --platform=darwin.venv/bin/python tests/regr_test.py stdlib --python-version 3.13npx pyright@1.1.411 stdlib/@tests/test_cases --pythonversion 3.13 -p pyrightconfig.testcases.json.venv/bin/python -m mypy.stubtest itertools --custom-typeshed-dir . --strict-type-check-onlyNote: the new overload is verified with pyright and ty; mypy does not yet propagate the exact iterator type through this overload (assert_type is disabled for mypy in the test case), and mypy_primer is clean.