`__hash__` with custom `__eq__`
Maintainers usually reply within 1 day
Nobody has claimed this yet.
Assessment
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Newbie friendliness
- 30/100
Research direction
Start with the minimal Python example and the PLW1641 diagnostic shown in the issue, then compare the attrs hashing documentation with Python's custom __eq__ and __hash__ rules. Done means establishing whether the behavior is expected and identifying a clear, agreed resolution or documentation change.
Written by the indexing model from the issue text.
Description
Hi, I know that hashing is a complicated topic and I've seen the sections in the docs / API reference + the resources linked therein. However, I'm still somewhat unclear about what is expected to happen in the situation described at the end.
Is this:
- expected?
- an attrs issue?
- a ruff issue?
And regardless of which it is, how to properly resolve it? The attrs docs say the following:
My understanding is that we are facing the highlighted case here, but I don't see the fallback to id-based hashing (regardless of whether I explicitly declare eq=True/False in the decorator) unless I add the __hash__ = object.__hash__ line.
Issue
from attrs import define
@define(frozen=True)
class C:
x: int
def __eq__(self, value):
return self.x in (0, value)
Gives the following ruff error:
PLW1641 Object does not implement `__hash__` method
--> dbg.py:5:7
|
4 | @define(frozen=True)
5 | class C:
| ^
6 | x: int
|
- Dominant language
- Python
- Stars
- 5.8k
- Forks
- 490
- Avg merge
- 3d 12h
- Merged PRs (30d)
- 3
Getting set up
- No Dockerfile or Docker Compose file
- Has a pull request template
- Read the contributing 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-attrs/attrs
-
Docs: `attrs.filters` is missing stated examplesPossibly taken @feiiiiii5 claimed this 10 days ago. Open
Difficulty 2/5 1-3 hours Newbie friendliness 78/100
python-attrs/attrs#1627 ·
Maintainers usually reply within 1 day
-
slots declared on attrs-decorated class are ignored/lostPossibly taken A pull request linked to this issue is open or already merged. Open
Difficulty 3/5 1-2 days Newbie friendliness 68/100
python-attrs/attrs#1637 ·
Maintainers usually reply within 1 day
-
Difficulty 5/5 Over a week Newbie friendliness 20/100
python-attrs/attrs#1620 ·
Maintainers usually reply within 1 day
-
Incorrect annotation for forward reference in generated constructorPossibly taken A pull request linked to this issue is open or already merged. Open
Difficulty 3/5 1-2 days Newbie friendliness 55/100
python-attrs/attrs#1596 · 2 comments · 1 reaction ·
Maintainers usually reply within 1 day
-
Decorated functions do not work with inheritancePossibly taken A pull request linked to this issue is open or already merged. Open
Difficulty 4/5 3-5 days Newbie friendliness 35/100
python-attrs/attrs#1549 · 3 comments ·
Maintainers usually reply within 1 day
All issues in python-attrs/attrs
Similar issues
-
feature:LinkChecker
Difficulty 2/5 1-3 hours Newbie friendliness 66/100
digitalfabrik/integreat-cms#4594 ·
Maintainers usually reply within 5 days
-
Difficulty 2/5 1-3 hours Newbie friendliness 78/100
Maintainers usually reply within 1 day
-
Difficulty 2/5 1-3 hours Newbie friendliness 70/100
EleutherAI/lm-evaluation-harness#4319 ·
Maintainers usually reply within 1 day
-
needs triage
Difficulty 2/5 1-3 hours Newbie friendliness 76/100
Maintainers usually reply within 1 day
-
json_params_matcher fails on falsy top-level JSON primitives (0, False, "")Possibly taken @mayureshsonawane17 claimed this today. OpenWaiting for: Product Owner
Difficulty 2/5 1-3 hours Newbie friendliness 84/100
Maintainers usually reply within 5 days