python / python/mypy

`Iterator[int]` not recognised as `Hashable`

Open
#21,813 0 comments 0 reactions 0 assignees View on GitHub

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

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

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. 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

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.