[Python-Dev] redefining is
mcherm at mcherm.com
Fri Mar 19 14:25:47 EST 2004
> Using == for identity objects is the wrong thing. We should discourage
> tests like "if obj == None" in favor of "if obj is None".
I hear you, but I disagree. There is a good reason why the default
implementation of '==' compares by object identity.
I don't care much whether we use "if obj is None" rather than
"if obj == None", since the PARTICULAR case of comparing with None
is mostly just an idiom. But if you have two different identity
objects and want to compare them, then I would prefer
if currentCustomer == desiredCustomer:
if currentCustomer is desiredCustomer:
However, either one works, and I won't gripe about your using 'is'
if you prefer it. I _WOULD_ gripe if you overrode __eq__ to raise
an exception in order to force me to use 'is' not '==' on your
objects (not that you ever suggested doing so).
-- Michael Chermside
More information about the Python-Dev