On 7/26/20 10:31 AM, Henry Lin wrote:
You're right, declaring `__eq__` for the class we want to compare would solve this issue. However, we have the tradeoff that
- All classes need to implement the `__eq__` method to compare two instances;
I usually implement __eq__ sooner or later anyway -- even if just for testing.
- Any class implementing the `__eq__` operator is no longer hashable
One just needs to define a __hash__ method that behaves properly.
- Developers might not want to leak the `__eq__` function to other developers; I wouldn't want to invade the implementation of my class just for testing.
And yet that's exactly what you are proposing with your object compare. If two objects are, in fact, equal, why is it bad for == to say so?