]> granicus.if.org Git - python/commitdiff
Marc-Andre Lemburg:
authorGuido van Rossum <guido@python.org>
Mon, 10 Apr 2000 13:42:33 +0000 (13:42 +0000)
committerGuido van Rossum <guido@python.org>
Mon, 10 Apr 2000 13:42:33 +0000 (13:42 +0000)
* TypeErrors during comparing of mixed type arguments including
  a Unicode object are now masked (just like they are for all
  other combinations).

Objects/object.c

index 265ab9b8347acd573a3b02a7b588064a7dffed02..968fdd0f23c6e4942702c7bb52a6680b2a239b5c 100644 (file)
@@ -347,8 +347,21 @@ PyObject_Compare(v, w)
                                return cmp;
                        }
                }
-               else if (PyUnicode_Check(v) || PyUnicode_Check(w))
-                       return PyUnicode_Compare(v, w);
+               else if (PyUnicode_Check(v) || PyUnicode_Check(w)) {
+                       int result = PyUnicode_Compare(v, w);
+                       if (result == -1 && PyErr_Occurred() && 
+                           PyErr_ExceptionMatches(PyExc_TypeError))
+                               /* TypeErrors are ignored: if Unicode coercion
+                               fails due to one of the arguments not
+                               having the right type, we continue as
+                               defined by the coercion protocol (see
+                               above). Luckily, decoding errors are
+                               reported as ValueErrors and are not masked
+                               by this technique. */
+                               PyErr_Clear();
+                       else
+                               return result;
+               }
                else if (vtp->tp_as_number != NULL)
                        vname = "";
                else if (wtp->tp_as_number != NULL)