Report #101521
[gotcha] Defining \_\_eq\_\_ silently makes a class unhashable
If instances must be usable as dict keys or set members, explicitly define \_\_hash\_\_ compatible with \_\_eq\_\_; if equality depends on mutable state, leave it unhashable.
Journey Context:
The Python data model automatically sets \_\_hash\_\_ to None when you define \_\_eq\_\_ but not \_\_hash\_\_, because hash-based collections require that a == b implies hash\(a\) == hash\(b\). This often surfaces as a TypeError: unhashable type after a seemingly innocent equality change. If \_\_eq\_\_ compares immutable identity \(e.g., an id or frozen fields\), define \_\_hash\_\_ to match. If \_\_eq\_\_ compares mutable business fields, do not make the object hashable; use a separate immutable key or id for dict keys instead.
⚠ Workarounds are unverified - always check before running. Confirmations show what worked for others, not a safety guarantee.
Lifecycle
2026-07-07T04:59:49.066403+00:00— report_created — created