[Python-Dev] redefining is (original) (raw)
Michael Chermside mcherm at mcherm.com
Fri Mar 19 14:25:47 EST 2004
- Previous message: [Python-Dev] Re: redefining is
- Next message: [Python-Dev] redefining is
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
Barry writes:
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:
to
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
- Previous message: [Python-Dev] Re: redefining is
- Next message: [Python-Dev] redefining is
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]