diff options
| author | Antoine Pitrou <solipsis@pitrou.net> | 2012-08-15 23:20:39 +0200 |
|---|---|---|
| committer | Antoine Pitrou <solipsis@pitrou.net> | 2012-08-15 23:20:39 +0200 |
| commit | da33e8cdc0c19f4a9e407f4a813fcf76870f35c2 (patch) | |
| tree | 1f95e72df9d6a969ae7e79759f6c926cbc98c509 /Objects | |
| parent | f9a713c7f197f14cd0e803ce9e00970a0c52dc07 (diff) | |
| parent | 1d494aa59c54cdf7d189b6b2e41502da941367b7 (diff) | |
| download | cpython-da33e8cdc0c19f4a9e407f4a813fcf76870f35c2.tar.gz | |
Issue #15604: Update uses of PyObject_IsTrue() to check for and handle errors correctly.
Patch by Serhiy Storchaka.
Diffstat (limited to 'Objects')
| -rw-r--r-- | Objects/typeobject.c | 12 |
1 files changed, 7 insertions, 5 deletions
diff --git a/Objects/typeobject.c b/Objects/typeobject.c index 2cc6eea465..a357ced220 100644 --- a/Objects/typeobject.c +++ b/Objects/typeobject.c @@ -383,11 +383,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__"); @@ -396,12 +400,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; } |
