Add a new function PyNumber_CoerceEx() which works just like
PyNumber_Coerce() except that when the coercion can't be done and no
other exceptions happen, it returns 1 instead of raising an
exception.

Use this function in PyObject_Compare() to avoid raising an exception
simply because two objects with numeric behavior can't be coerced to a
common type; instead, proceed with the non-numeric default comparison.

Note that this is a somewhat questionable practice -- comparisons for
numeric objects shouldn't default to random behavior like this, but it
is required for backward compatibility.  (Case in point, it broke
comparison of kjDict objects to integers in Aaron Watters' kjbuckets
extension.)  A correct fix (for python 2.0) should involve a different
definiton of comparison altogether.
1 file changed