mirror of
https://github.com/python/cpython.git
synced 2025-11-01 18:51:43 +00:00
Slightly revised version of patch #1538956:
Replace UnicodeDecodeErrors raised during == and != compares of Unicode and other objects with a new UnicodeWarning. All other comparisons continue to raise exceptions. Exceptions other than UnicodeDecodeErrors are also left untouched.
This commit is contained in:
parent
e6dd31c50b
commit
040f76b79c
11 changed files with 170 additions and 36 deletions
|
|
@ -731,23 +731,6 @@ default_3way_compare(PyObject *v, PyObject *w)
|
|||
return (vv < ww) ? -1 : (vv > ww) ? 1 : 0;
|
||||
}
|
||||
|
||||
#ifdef Py_USING_UNICODE
|
||||
/* Special case for Unicode */
|
||||
if (PyUnicode_Check(v) || PyUnicode_Check(w)) {
|
||||
c = PyUnicode_Compare(v, w);
|
||||
if (!PyErr_Occurred())
|
||||
return c;
|
||||
/* 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. */
|
||||
if (!PyErr_ExceptionMatches(PyExc_TypeError))
|
||||
return -2;
|
||||
PyErr_Clear();
|
||||
}
|
||||
#endif
|
||||
|
||||
/* None is smaller than anything */
|
||||
if (v == Py_None)
|
||||
return -1;
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue