On Mon, Jul 6, 2020, at 01:47, Neil Girdhar wrote:
Are all objects in Python equality-comparable? I know that you can delete __hash__ to make an object unhashable (e.g., dicts). If so, this is a great addition.
Anyone can in principle override __eq__ to throw an exception, but they're not "supposed to" - the default behavior is that an object is only equal to itself, and floating point NaNs aren't equal to anything including itself which isn't very useful, but in all cases the operation itself is valid and simply returns false e.g. when the other operand is a different type rather than treating it as any kind of error.
Which of course means that, right now, a sequence that does not define its own __eq__ method is equal only to itself, rather than it being an error to try to compare it.