mirror of
https://github.com/python/cpython.git
synced 2025-09-26 18:29:57 +00:00
Issue #15604: Update uses of PyObject_IsTrue() to check for and handle errors correctly.
Patch by Serhiy Storchaka.
This commit is contained in:
parent
4ffe9a0640
commit
c5bef75c77
11 changed files with 112 additions and 52 deletions
|
@ -327,11 +327,15 @@ type_set_abstractmethods(PyTypeObject *type, PyObject *value, void *context)
|
|||
abc.ABCMeta.__new__, so this function doesn't do anything
|
||||
special to update subclasses.
|
||||
*/
|
||||
int res;
|
||||
int abstract, res;
|
||||
if (value != NULL) {
|
||||
abstract = PyObject_IsTrue(value);
|
||||
if (abstract < 0)
|
||||
return -1;
|
||||
res = PyDict_SetItemString(type->tp_dict, "__abstractmethods__", value);
|
||||
}
|
||||
else {
|
||||
abstract = 0;
|
||||
res = PyDict_DelItemString(type->tp_dict, "__abstractmethods__");
|
||||
if (res && PyErr_ExceptionMatches(PyExc_KeyError)) {
|
||||
PyErr_SetString(PyExc_AttributeError, "__abstractmethods__");
|
||||
|
@ -340,12 +344,10 @@ type_set_abstractmethods(PyTypeObject *type, PyObject *value, void *context)
|
|||
}
|
||||
if (res == 0) {
|
||||
PyType_Modified(type);
|
||||
if (value && PyObject_IsTrue(value)) {
|
||||
if (abstract)
|
||||
type->tp_flags |= Py_TPFLAGS_IS_ABSTRACT;
|
||||
}
|
||||
else {
|
||||
else
|
||||
type->tp_flags &= ~Py_TPFLAGS_IS_ABSTRACT;
|
||||
}
|
||||
}
|
||||
return res;
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue