summaryrefslogtreecommitdiffstats
path: root/Objects
diff options
context:
space:
mode:
authorJeremy Hylton <jeremy@alum.mit.edu>2007-08-29 18:47:16 (GMT)
committerJeremy Hylton <jeremy@alum.mit.edu>2007-08-29 18:47:16 (GMT)
commit18c3ff887f95e7b566b36faf97d457372c04c213 (patch)
treed2d1242b8c7eca59638696b43b95004f64384e3e /Objects
parent991bf5d8c8fdd94c3b9238d7111c0dfb41973804 (diff)
downloadcpython-18c3ff887f95e7b566b36faf97d457372c04c213.zip
cpython-18c3ff887f95e7b566b36faf97d457372c04c213.tar.gz
cpython-18c3ff887f95e7b566b36faf97d457372c04c213.tar.bz2
Make it an error to compare a bytes object and a Unicode object.
Diffstat (limited to 'Objects')
-rw-r--r--Objects/bytesobject.c10
1 files changed, 8 insertions, 2 deletions
diff --git a/Objects/bytesobject.c b/Objects/bytesobject.c
index b267cac..c132692 100644
--- a/Objects/bytesobject.c
+++ b/Objects/bytesobject.c
@@ -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) {