RichCompare and RichCompareBool

Duncan Booth duncan.booth at invalid.invalid
Mon Mar 2 12:00:45 CET 2009


Aaron Brady <castironpi at gmail.com> wrote:

> Hi,
> 
> In the source for 3.0.1, PyObject_RichCompareBool seems to perform an
> extra check on identity that PyObjecct_RichCompare does not perform.
> 
> Here's the excerpt from RichCompareBool (line 612):
> 
>      /* 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;
>      }
> 
>      res = PyObject_RichCompare(v, w, op);
> 
> The code for PyObject_RichCompare does not contain this, it doesn't
> seem.  Is it a bug?

Without looking at the code it sounds like a bug: identity doesn't always 
imply equality.

It may be that the code you've found only gets called in specific cases 
where you can make that assumption, but otherwise it should be removed.

-- 
Duncan Booth http://kupuguy.blogspot.com



More information about the Python-list mailing list