Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit b244f69

Browse files
committed
Marc-Andre Lemburg:
* TypeErrors during comparing of mixed type arguments including a Unicode object are now masked (just like they are for all other combinations).
1 parent 52c2359 commit b244f69

1 file changed

Lines changed: 15 additions & 2 deletions

File tree

Objects/object.c

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -347,8 +347,21 @@ PyObject_Compare(v, w)
347347
return cmp;
348348
}
349349
}
350-
else if (PyUnicode_Check(v) || PyUnicode_Check(w))
351-
return PyUnicode_Compare(v, w);
350+
else if (PyUnicode_Check(v) || PyUnicode_Check(w)) {
351+
int result = PyUnicode_Compare(v, w);
352+
if (result == -1 && PyErr_Occurred() &&
353+
PyErr_ExceptionMatches(PyExc_TypeError))
354+
/* TypeErrors are ignored: if Unicode coercion
355+
fails due to one of the arguments not
356+
having the right type, we continue as
357+
defined by the coercion protocol (see
358+
above). Luckily, decoding errors are
359+
reported as ValueErrors and are not masked
360+
by this technique. */
361+
PyErr_Clear();
362+
else
363+
return result;
364+
}
352365
else if (vtp->tp_as_number != NULL)
353366
vname = "";
354367
else if (wtp->tp_as_number != NULL)

0 commit comments

Comments
 (0)