Skip to content

Recognize Iterator as Hashable - #21837

Draft
aryansk wants to merge 1 commit into
python:masterfrom
aryansk:codex/mypy-21813
Draft

Recognize Iterator as Hashable#21837
aryansk wants to merge 1 commit into
python:masterfrom
aryansk:codex/mypy-21813

Conversation

@aryansk

@aryansk aryansk commented Aug 12, 2026

Copy link
Copy Markdown

Fixes #21813

Summary

  • Add hash to typing.Iterator in the stdlib typing stub.
  • Mirror the protocol member in the unit-test typing fixture.
  • Add a regression check showing Iterator[str] satisfies Hashable while Iterable[str] does not.

Tests

  • runtests.py check-protocols.test: 200 passed, 1 skipped.
  • The issue reproducer now reports no errors.

This PR was prepared with AI assistance, as permitted by the contributor guidance, and the implementation and test results were reviewed locally.

@github-actions

This comment has been minimized.

@aryansk

aryansk commented Aug 12, 2026

Copy link
Copy Markdown
Author

Thanks for the primer report. The original stub change was too broad: it made Iterator.__hash__ mandatory and caused downstream regressions. I amended the PR at a0f382aa2763f4ec94bb3968dd3a2638614b8661 to handle the standard Iterator-to-Hashable relation in subtype checking, with regression coverage for the issue reproducer and an unhashable Iterator subclass. Local check-protocols.test passes (200 passed, 1 skipped); hosted checks are rerunning.

@github-actions

Copy link
Copy Markdown
Contributor

Diff from mypy_primer, showing the effect of this PR on open source code:

pandas-stubs (https://github.com/pandas-dev/pandas-stubs)
+ tests/frame/test_indexing.py:458: error: Unused "type: ignore[index]" comment  [unused-ignore]

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.

Iterator[int] not recognised as Hashable

1 participant