Author rhettinger
Recipients barry, christian.heimes, gvanrossum, mark.dickinson, mikecurtis, rhettinger
Date 2008-11-11.13:10:47
SpamBayes Score 1.55174e-09
Marked as misclassified No
Message-id <1226409049.8.0.998276133203.issue4296@psf.upfronthosting.co.za>
In-reply-to
Content
To be clear, I'm saying that PyObject_RichCompareBool() needs to
add-back the code:

	/* Quick result when objects are the same.
	   Guarantees that identity implies equality. */
	if (v == w) {
		if (op == Py_EQ)
			return 1;
		else if (op == Py_NE)
			return 0;
	}

When the above code was originally put in, there was discussion about it
on python-dev and time has proven it to be a successful choice.  

I don't know who took this out, but taking it out was a mistake in a
world that allows rich comparison functions to return anything they
want, possibly screwing-up the basic invariants everywhere we do
membership testing.  

Taking it out probably had something to do with NaNs, but this
discussion needs to avoid getting lost in NaN paradoxes and instead
focus on a notion of membership that is ALWAYS true given object
identity.  This is an essential pragmatism necessary for reasoning about
programs.

Consider that while PyObject_RichCompare() can return any object and can
be used in varied and sundry ways, the opposite is true for
PyObject_RichCompareBool().  The latter always returns a boolean and its
internal use cases are almost always ones that assume the traditional
properties of equality  -- a binary relation or predicate that is
reflexive, symmetric, and transitive.  We let the == operator violate
those properties, but the calls to PyObject_RichCompareBool() tend to
DEPEND on them.

---------------------------------------------------------------
P.S.  Mark, those Py2.6 invariants are not still true in Py3.0:

   IDLE 3.0rc2      
   >>> a = float('nan')
   >>> a in [a]
   False
   >>> a in (a,)
   False
   >>> a in set([a])
   True
   >>> [a].count(a)
   0
   >>> for x in container:
   	assert x in container
	
   AssertionError
History
Date User Action Args
2008-11-11 13:10:50rhettingersetrecipients: + rhettinger, gvanrossum, barry, mark.dickinson, christian.heimes, mikecurtis
2008-11-11 13:10:49rhettingersetmessageid: <1226409049.8.0.998276133203.issue4296@psf.upfronthosting.co.za>
2008-11-11 13:10:49rhettingerlinkissue4296 messages
2008-11-11 13:10:47rhettingercreate