mirror of
https://github.com/python/cpython.git
synced 2025-10-08 08:01:55 +00:00
Issue #23681: The -b option now affects comparisons of bytes with int.
This commit is contained in:
parent
ee4c0b9dcf
commit
1dd49824df
5 changed files with 53 additions and 22 deletions
|
@ -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;
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue