]> granicus.if.org Git - python/commit
Add a new function PyNumber_CoerceEx() which works just like
authorGuido van Rossum <guido@python.org>
Wed, 19 Nov 1997 16:03:17 +0000 (16:03 +0000)
committerGuido van Rossum <guido@python.org>
Wed, 19 Nov 1997 16:03:17 +0000 (16:03 +0000)
commit242c64256c03f94e043a7528ff5b7e0220262d8d
treecf7926ca560c912fccd7107f68c424833ec3ace1
parent220ecc8c4b3891c1d6eb7e59f8e8b38ac706d25b
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.
Objects/object.c