MyPy does not enforce Hashability
Nobody has claimed this yet.
Assessment
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Newbie friendliness
- 35/100
Research direction
The report points to checker.py; start by tracing how mypy validates set elements and whether existing Protocol checks are handled there. Reproduce the Python 3 example and compare it with the expected rejection of Foo in a set. Done means the checker reports the unhashable class while preserving valid hashable cases.
Written by the indexing model from the issue text.
Description
For example, the following code is illegal in Python 3 (implementing __eq__ shadows your __hash__ implementation with None in Python 3)
class Foo(object):
def __init__(self, x):
self.x = x
def __eq__(self, other):
if not isinstance(other, Foo):
return NotImplemented
return self.x == other.x
set_of_foo = {Foo(1), Foo(2)}
Poking around the code, AFAICT mypy doesn't do any Hashable checks. I don't see any other Protocols being checked in checker.py. Is there any existing tickets around supporting Protocols in mypy?
- Dominant language
- Python
- Stars
- 20.6k
- Forks
- 3.3k
- Avg merge
- 1d 18h
- Merged PRs (30d)
- 54
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.
More from python/mypy
-
bug
Difficulty 2/5 1-3 hours Newbie friendliness 75/100
-
bug
Difficulty 2/5 1-3 hours Newbie friendliness 78/100
-
bug
Difficulty 2/5 1-3 hours Newbie friendliness 76/100
-
documentation
Difficulty 2/5 1-3 hours Newbie friendliness 72/100
-
bug topic-configuration topic-error-reporting
Difficulty 2/5 1-3 hours Newbie friendliness 68/100