why () is () and [] is [] work in other way?
Chris Angelico
rosuav at gmail.com
Thu Apr 26 10:36:20 EDT 2012
On Fri, Apr 27, 2012 at 12:00 AM, Adam Skutt <askutt at gmail.com> wrote:
> C# and Python do have a misfeature: '==' is identity comparison only
> if operator== / __eq__ is not overloaded. Identity comparison and
> value comparison are disjoint operations, so it's entirely
> inappropriate to combine them.
So what should happen if you don't implement __eq__? Should the ==
operator throw an exception? This can be done fairly easily:
class object(object):
def __eq__(self,other):
raise NoYouDontException("Naughty programmer, mustn't do that!")
(Works only if you always explicitly subclass object, even though
that's not necessary in Python 3.)
ChrisA
More information about the Python-list
mailing list