[docs] [issue12067] Doc: remove errors about mixed-type comparisons.

Terry J. Reedy report at bugs.python.org
Fri Jul 4 21:24:07 CEST 2014

Terry J. Reedy added the comment:

In py3, *everything* is an instance of class object. This makes like simple than in 2.x. The default comparison rules are set by the rich comparison methods of object. 'By experiment' meant by experiments with instances of object, which use those default methods, rather than by inspection of the relevant .c source code. Instances of subclasses taht do not override the defaults would act the same. Here is what seem to be the default code, from object.c, do_compare.  It verifies what I said (v, w are pointers, which represent identity):

    /* If neither object implements it, provide a sensible default
       for == and !=, but raise an exception for ordering. */
    switch (op) {
    case Py_EQ:
        res = (v == w) ? Py_True : Py_False;
    case Py_NE:
        res = (v != w) ? Py_True : Py_False;
        /* XXX Special-case None so it doesn't show as NoneType() */
                     "unorderable types: %.100s() %s %.100s()",
        return NULL;
    return res;

Subclasses can and ofter do override the default methods. In particular, the number subclasses compare by value, across number types.


Python tracker <report at bugs.python.org>

More information about the docs mailing list