Shane Hathaway wrote:
Jeremy Hylton wrote: <snip>
Actually, C++ generates a compiler error if you try to do that. (See
the attached program.) Java doesn't run into this because it has a
simpler interface: the only operator you can override is equals(). So
in this case, C++ is fully explicit and Java is fully implicit, while
Python makes a guess. If we can't make it implicit like Java, then it
seems preferable for Python to raise an exception, similar to C++, when
you use the != operator with an instance that implements __eq__ but not
__ne__.
Shane
Jeremy Hylton wrote: <snip>
Actually, C++ generates a compiler error if you try to do that. (See
the attached program.) Java doesn't run into this because it has a
simpler interface: the only operator you can override is equals(). So
in this case, C++ is fully explicit and Java is fully implicit, while
Python makes a guess. If we can't make it implicit like Java, then it
seems preferable for Python to raise an exception, similar to C++, when
you use the != operator with an instance that implements __eq__ but not
__ne__.
Shane
+1
would be probably very helpful
The only problem I see is that it would break "perlish" code (code you
would not understand the behaviour of 3 weeks later). Of course some
code might never use the __ne__ of its "__eq__ overloaded class" and
therefore lived happily so far, but it is dangerous code anyway.
Regards, Ben.