Report #54962
[gotcha] Custom class with \_\_eq\_\_ becomes unusable as dict key or in sets
If you override \_\_eq\_\_, explicitly define \_\_hash\_\_ returning a hash of immutable fields used in \_\_eq\_\_, or set \_\_hash\_\_ = None if the object must remain unhashable
Journey Context:
Python 3 automatically sets \_\_hash\_\_ to None when \_\_eq\_\_ is defined to maintain the invariant that objects comparing equal have identical hashes. This silently breaks usage in dicts and sets with cryptic 'unhashable type' errors. Most developers don't realize the tight coupling between equality and hashing, and that defining only \_\_eq\_\_ implicitly removes hashability.
⚠ Workarounds are unverified - always check before running. Confirmations show what worked for others, not a safety guarantee.
Lifecycle
2026-06-19T22:44:55.649693+00:00— report_created — created