Issue #23681: The -b option now affects comparisons of bytes with int.

This commit is contained in:
Serhiy Storchaka 2015-03-20 16:54:57 +02:00
parent ee4c0b9dcf
commit 1dd49824df
5 changed files with 53 additions and 22 deletions

View file

@ -1385,14 +1385,23 @@ bytes_richcompare(PyBytesObject *a, PyBytesObject *b, int op)
/* Make sure both arguments are strings. */
if (!(PyBytes_Check(a) && PyBytes_Check(b))) {
if (Py_BytesWarningFlag && (op == Py_EQ || op == Py_NE) &&
(PyObject_IsInstance((PyObject*)a,
(PyObject*)&PyUnicode_Type) ||
PyObject_IsInstance((PyObject*)b,
(PyObject*)&PyUnicode_Type))) {
if (PyErr_WarnEx(PyExc_BytesWarning,
"Comparison between bytes and string", 1))
return NULL;
if (Py_BytesWarningFlag && (op == Py_EQ || op == Py_NE)) {
if (PyObject_IsInstance((PyObject*)a,
(PyObject*)&PyUnicode_Type) ||
PyObject_IsInstance((PyObject*)b,
(PyObject*)&PyUnicode_Type)) {
if (PyErr_WarnEx(PyExc_BytesWarning,
"Comparison between bytes and string", 1))
return NULL;
}
else if (PyObject_IsInstance((PyObject*)a,
(PyObject*)&PyLong_Type) ||
PyObject_IsInstance((PyObject*)b,
(PyObject*)&PyLong_Type)) {
if (PyErr_WarnEx(PyExc_BytesWarning,
"Comparison between bytes and int", 1))
return NULL;
}
}
result = Py_NotImplemented;
}