gh-108511: Add C API functions which do not silently ignore errors (GH-109025)

Add the following functions:

* PyObject_HasAttrWithError()
* PyObject_HasAttrStringWithError()
* PyMapping_HasKeyWithError()
* PyMapping_HasKeyStringWithError()
This commit is contained in:
Serhiy Storchaka 2023-09-17 14:23:31 +03:00 committed by GitHub
parent e57ecf6bbc
commit add16f1a5e
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
28 changed files with 330 additions and 111 deletions

View file

@ -3879,16 +3879,14 @@ type_new_get_bases(type_new_ctx *ctx, PyObject **type)
if (PyType_Check(base)) {
continue;
}
PyObject *mro_entries;
if (PyObject_GetOptionalAttr(base, &_Py_ID(__mro_entries__),
&mro_entries) < 0) {
int rc = PyObject_HasAttrWithError(base, &_Py_ID(__mro_entries__));
if (rc < 0) {
return -1;
}
if (mro_entries != NULL) {
if (rc) {
PyErr_SetString(PyExc_TypeError,
"type() doesn't support MRO entry resolution; "
"use types.new_class()");
Py_DECREF(mro_entries);
return -1;
}
}