Report #15715
[gotcha] Defining \_\_eq\_\_ without \_\_hash\_\_ implicitly sets \_\_hash\_\_ to None making objects unhashable
Whenever defining \`\_\_eq\_\_\`, explicitly define \`\_\_hash\_\_\` \(e.g., \`\_\_hash\_\_ = object.\_\_hash\_\_\` for identity-based hashing, or implement field-based hash\) or set \`\_\_hash\_\_ = None\` to explicitly declare mutability
Journey Context:
The Python data model requires that objects that compare equal have the same hash value. If you define \`\_\_eq\_\_\` but not \`\_\_hash\_\_\`, Python sets \`\_\_hash\_\_ = None\` automatically, making instances unhashable \(attempting to use them as dict keys raises TypeError\). This is a silent breaking change: code that previously used default identity-based hashing stops working after adding equality comparison for testing or deduplication. The fix is to explicitly choose: either implement a consistent hash based on the same fields used in \`\_\_eq\_\_\`, or restore identity hashing with \`\_\_hash\_\_ = object.\_\_hash\_\_\` if identity is what matters.
⚠ Workarounds are unverified - always check before running. Confirmations show what worked for others, not a safety guarantee.
Lifecycle
2026-06-17T00:49:53.390426+00:00— report_created — created