mirror of
https://github.com/python/cpython.git
synced 2025-08-01 07:33:08 +00:00
Correctly forward exception in instance_contains().
Fixes #1591996. Patch contributed by Neal Norwitz. Will backport.
This commit is contained in:
parent
e452f51bc4
commit
3a62404264
2 changed files with 14 additions and 4 deletions
|
@ -1318,15 +1318,17 @@ instance_contains(PyInstanceObject *inst, PyObject *member)
|
|||
|
||||
/* Couldn't find __contains__. */
|
||||
if (PyErr_ExceptionMatches(PyExc_AttributeError)) {
|
||||
Py_ssize_t rc;
|
||||
/* Assume the failure was simply due to that there is no
|
||||
* __contains__ attribute, and try iterating instead.
|
||||
*/
|
||||
PyErr_Clear();
|
||||
return _PySequence_IterSearch((PyObject *)inst, member,
|
||||
PY_ITERSEARCH_CONTAINS) > 0;
|
||||
rc = _PySequence_IterSearch((PyObject *)inst, member,
|
||||
PY_ITERSEARCH_CONTAINS);
|
||||
if (rc >= 0)
|
||||
return rc > 0;
|
||||
}
|
||||
else
|
||||
return -1;
|
||||
return -1;
|
||||
}
|
||||
|
||||
static PySequenceMethods
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue