Raymond Hettinger <[EMAIL PROTECTED]> added the comment: 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 _______________________________________ Python tracker <[EMAIL PROTECTED]> <http://bugs.python.org/issue4296> _______________________________________ _______________________________________________ Python-bugs-list mailing list Unsubscribe: http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com