dict_keys is identified as hashable
Open
Nobody has claimed this yet.
bug
- Dominant language
- Python
- Stars
- 20.6k
- Forks
- 3.3k
- PR merge metrics
- PR metrics pending
Description
Bug Report
Mypy seems to think that dict_keys ({}.keys()) are hashable, which they are not.
To Reproduce
def f(a: Hashable) -> int:
return 1
f({}.keys()) # does not raise an issue
Expected Behavior
Since dict-keys are not hashable (hash({}.keys()) fails and isinstance({}.keys(), Hashable) == False) I would expect mypy to throw an error in the above example.
Actual Behavior
Success: no issues found in 1 source file
Your Environment
- Mypy version used: 0.982
- Mypy command-line flags: /
- Mypy configuration options from
mypy.ini(and other config files): / - Python version used: 3.10.8
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 by running the provided Python reproducer with mypy and tracing how dict_keys is checked against Hashable. Done means mypy reports an error for f({}.keys()) and a regression test covers the behavior.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- python
- Domain
- devtools
- Issue type
- Bug
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 38/100