Hacktoberfest 2026: le issue che i maintainer hanno segnato per ottobre, aperte e adatte ai principianti. Sfoglia le issue Hacktoberfest

`__hash__` with custom `__eq__`

Aperta
#1,462 2 commenti 0 reazioni 0 assegnatari Vedi su GitHub

Nessuno ha ancora preso questa issue.

Valutazione

Difficoltà
4/5
Tempo stimato
3-5 giorni
Idoneità per principianti
30/100
Tipo di issue
Documentazione
Chiarezza
Da chiarire
Stato di attività
Ferma
Stack tecnologico
python
Ambito
tooling

Direzione di ricerca

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.

Scritto dal modello di indicizzazione a partire dal testo della issue.

Descrizione

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:

Image

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
  |
Lingua principale
Python
Stelle
5.8k
Fork
480
Merge medio
2h 15m
PR unite (30g)
2

Guida per i contributori

Apri la guida per i contributori

Come iniziare

  1. Leggi tutta la issue e poi la guida ai contributi del progetto.
  2. Commenta sulla issue per dire che te ne occupi tu — evita che due persone facciano lo stesso lavoro.
  3. Fai un fork del repository e lavora su un branch.
  4. Apri una pull request che faccia riferimento al numero della issue.

Altre issue di python-attrs/attrs

Tutte le issue di python-attrs/attrs

Issue simili

Altre issue su Python

Ricevi le nuove issue nella tua casella

Un breve riepilogo di issue GitHub adatte ai principianti.