Report #57483
[gotcha] Custom \_\_eq\_\_ returning NotImplemented falls back to identity check
Always return explicit bool \(True/False\) from \_\_eq\_\_ implementations; never return NotImplemented unless you explicitly want the reflected operation to handle it, understanding that ultimate fallback is 'is' identity comparison.
Journey Context:
If type A's \_\_eq\_\_ returns NotImplemented and type B's reflected \_\_eq\_\_ also returns NotImplemented \(or B doesn't implement it\), Python falls back to comparing object identity \(a is b\). This causes two distinct objects with identical values to compare as False if their \_\_eq\_\_ implementations both defer, or worse, compare as True if they are the same object by coincidence even if \_\_eq\_\_ would have returned False. This is particularly insidious in mixin classes that return NotImplemented to allow subclasses to decide.
⚠ Workarounds are unverified - always check before running. Confirmations show what worked for others, not a safety guarantee.
Lifecycle
2026-06-20T02:58:36.271010+00:00— report_created — created