[Python-Dev] redefining is

Barry Warsaw barry at python.org
Fri Mar 19 12:55:25 EST 2004


On Fri, 2004-03-19 at 12:19, Andrew Koenig wrote:

> The original author of the proposal on comp.lang.python was clearly
> disturbed at getting object identity when equivalence would have made more
> sense, and was proposing to change things as follows:
> 
> 	x == y		Value equality
> 
> 	x is y		Object equivalence
> 
> 	id(x) == id(y)	Object identity
> 
> I can completely understand why this change might be considered too large to
> make to an existing language--just like changing the wan C++ handles virtual
> destructors would be--but nevertheless I think it's interesting to consider
> the abstract merits of an idea such as this one, perhaps for the mythical
> Python 3.0.

I understand your argument, and have some sympathy for it, but I don't
think that 'is' should be the way to spell object equivalence.  If
someone asks "Tim is Barry" I would expect they want an identity test,
not an equivalence test, otherwise they might not get the geezin' Python
hacker they wanted even though as bass players and Britney Spears
fanatics, we're completely substitutable.

IIRC, id() has problems on Jython also, so relying on that for identity
doesn't seem right either.

Also, since we don't really know what "object equivalence" means in a
practical sense, I don't know what we'd be spelling.  But if we do
figure it out (and can explain it in a way people can understand it),
and find that it's an important enough concept to want to express, we'd
need a Different Way to spell it in Python.  To me, "is" asks "are these
two things the same thing" not "could these two things serve the same
purpose".  An English word (not mathematical symbol) was chosen for this
concept for a reason.

Maybe we need a 'like' keyword-let to spell equivalence:

   >>> "hello" is like 'hello'
   True

-Barry

PS: 'raise "quit"' doesn't really enter into this for two reasons. 
First, string exceptions are going away.  Second, there's no 'is'
there.  If string exceptions were to stick around, then it might make
sense to redefine the match criteria in terms of object equivalence. 
But that's a moot point.





More information about the Python-Dev mailing list