`Iterator[int]` not recognised as `Hashable`
Open
Nobody has claimed this yet.
bug
topic-protocols
- Dominant language
- Python
- Stars
- 20.6k
- Forks
- 3.3k
- PR merge metrics
- PR metrics pending
Description
Bug Report
Iterator[int] is not recognised as Hashable.
To Reproduce
- https://play.ty.dev/13380319-febd-421a-9540-ce987c4bbc9c
- https://pyrefly.org/sandbox/?project=v2.lVVBboMwEPzKqjlgWoJL1RMPqHrs3eWAUgSWmoCwqZJD_95Zg8GoSZRckGV21-uZ2fEdlvnoBcqlxTEH_NbrZdLKkZ4o47DAk4QLf32JQcp_zDb0MW7QdDzcAmDXAzwJIKafhw3sqKLG2s7kUvr0tq9ldZBf7c7IVYYklkf5U2rndOty1DqODcqeJyu7iaxo5Cq6RlXETCFirw0Grd6aoav67Q4iwk8LWQKLBXHtIb9g3Mvz8V6ahi-2-Bmb4FuP0Vk5mqksTwJMbe1bCaHNnOwAC1TmW4c1i9n7_HkKHAMHTl5mmdIUADIz-1N3IlwCShmHJqGJILeLta4b9nOetLlPEadhf8J1Ibg0HtL5Gyc83L1Qz0WMtcoKCCioofIgoACoiIDCLotdP_z-AQ
- https://pyright-play.net/?code=GYJw9gtgBAxmA28CmMAuBLMA7AzgOgEMAjGKdCABzBFSgGUkBHAVySxiQBooAJAnABbFkAKBEx4-HFAAiBVAQBiIAhCQAuEVG1QAJkmBQA%2BkZxIMqJBBMAKLTodn4wbgGskAT3VRUzCsgBtHHh0Dm4%2BQWEkAF1uADcCeFZvBhY2DgD0LFRo%2B20ASigAWgA%2BKAA5bA0oPFqxAGIoCA8KDygCLF0fNqQQcBBuVpADeDaOrqH0AHMBWgopETkFZVUkG3y8EzMLK1sbYNC1yqwuCqruY6R87nRLEBsAgAZo-OuoAIBGF8X5JRU1dYBdQ3O4PZ75aJQAC87y%2BIiAA
- https://mypy-play.net/?gist=71aba787eb6f23212e1fd4e0a63cf86f
from collections.abc import Sequence, Hashable
class DataFrame:
def __setitem__(
self, key: tuple[slice, Hashable], value: Sequence[int]
) -> None: ...
# mypy and ty error, pyrefly and pyright pass
DataFrame().__setitem__((slice(None, None, None), iter([0])), [1])
DataFrame()[:, iter([0])] = [1]
Expected Behavior
error free
Actual Behavior
main.py:9: error: Invalid index type "tuple[slice[Any, Any, Any], Iterator[int]]" for "DataFrame"; expected type "tuple[slice[Any, Any, Any], Hashable]" [index]
main.py:10: error: Invalid index type "tuple[slice[None, None, None], Iterator[int]]" for "DataFrame"; expected type "tuple[slice[Any, Any, Any], Hashable]" [index]
Found 2 errors in 1 file (checked 1 source file)
Your Environment
Playground
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start with the main.py reproducer in the linked mypy playground and run mypy to confirm the invalid index type diagnostic. Trace how Iterator[int] is checked against Hashable, then verify the reproducer is error-free while preserving the expected tuple index types.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- python
- Domain
- compilers
- Issue type
- Bug
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Activity status
- Quiet
- Clarity
- Mostly clear
- Newbie friendliness
- 55/100