mirror of
https://github.com/python/cpython.git
synced 2025-11-01 02:38:53 +00:00
Issue #24115: Update uses of PyObject_IsTrue(), PyObject_Not(),
PyObject_IsInstance(), PyObject_RichCompareBool() and _PyDict_Contains() to check for and handle errors correctly.
This commit is contained in:
parent
50451eb912
commit
fa494fd883
10 changed files with 83 additions and 36 deletions
|
|
@ -974,13 +974,17 @@ bytearray_richcompare(PyObject *self, PyObject *other, int op)
|
|||
Py_buffer self_bytes, other_bytes;
|
||||
PyObject *res;
|
||||
Py_ssize_t minsize;
|
||||
int cmp;
|
||||
int cmp, rc;
|
||||
|
||||
/* 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)) {
|
||||
rc = PyObject_IsInstance(self, (PyObject*)&PyUnicode_Type);
|
||||
if (!rc)
|
||||
rc = PyObject_IsInstance(other, (PyObject*)&PyUnicode_Type);
|
||||
if (rc < 0)
|
||||
return NULL;
|
||||
if (rc) {
|
||||
if (Py_BytesWarningFlag && (op == Py_EQ || op == Py_NE)) {
|
||||
if (PyErr_WarnEx(PyExc_BytesWarning,
|
||||
"Comparison between bytearray and string", 1))
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue