Result of ``a is b''

Carl Banks imbosol at aerojockey.invalid
Thu Mar 18 22:58:54 EST 2004


Steve wrote:
> 
> 
> Asun Friere wrote:
> 
>> In fact __eq__ can be redefined even /so as to be an equivalence
>> relation/ such that x==y => True and x is y => False.  The
>> 'fundamental properties' posisted, are simply not fundamental.
> 
> I think you have mis-read those fundamental properties. 
> They were:
> 
> (1) If x and y refer to the same object, "x is y" 
> yields True.
> 
> (2) If "x is y" yields True, "x==y" also yields True. 
> Equivalently, if "x==y" yields False, "x is y" also 
> yields False.
> 
> Property (2) assumes that __eq__ implements an 
> equivalence relation.
> 
> Notice that your objection that x==y returns True and x 
> is y returns False is *not* one of those properties. In 
> fact, that is the normal behaviour:
> 
> >>> a = [1, 2]
> >>> b = [1] + [2]
> >>> (a == b, a is b)
> (1, 0)
> 
> I don't think the argument that one can redefine __eq__ 
> to be something other than an equivalence relation is a 
> particularly strong argument. I would call that a bug, 
> even if it is a deliberate bug. If "==" doesn't do 
> equality, then it is an exceedingly bad piece of design.


You know, it's not hard to imagine some abstract mathematical superset
of the normal orthogonal math we use everyday, wherein certain numbers
(or sets or whatever) are not equal to themselves.  In which case it
would be entirely appropriate for __eq__ to return False if called
with the same object.  Of course, that's not really the typical case.

(It's also not hard to imagine that, if such a branch of mathematics
exists, someone here will know about it.)


-- 
CARL BANKS                      http://www.aerojockey.com/software
"If you believe in yourself, drink your school, stay on drugs, and
don't do milk, you can get work." 
          -- Parody of Mr. T from a Robert Smigel Cartoon



More information about the Python-list mailing list