Make it an error to compare a bytes object and a Unicode object.

This commit is contained in:
Jeremy Hylton 2007-08-29 18:47:16 +00:00
parent 991bf5d8c8
commit 18c3ff887f
2 changed files with 13 additions and 7 deletions

View file

@ -959,8 +959,14 @@ bytes_richcompare(PyObject *self, PyObject *other, int op)
Py_ssize_t minsize;
int cmp;
/* Bytes can be compared to anything that supports the (binary) buffer
API. Except Unicode. */
/* Bytes can be compared to anything that supports the (binary)
buffer API. Except that a comparison with Unicode is always an
error, even if the comparison is for equality. */
if (PyObject_IsInstance(self, (PyObject*)&PyUnicode_Type) ||
PyObject_IsInstance(other, (PyObject*)&PyUnicode_Type)) {
PyErr_SetString(PyExc_TypeError, "can't compare bytes and str");
return NULL;
}
self_size = _getbuffer(self, &self_bytes);
if (self_size < 0) {