mirror of
https://github.com/python/cpython.git
synced 2025-11-01 18:51:43 +00:00
don't segfault on deleting __abstractmethods__ #10892
This commit is contained in:
parent
5e8dada491
commit
477ba919c1
3 changed files with 19 additions and 3 deletions
|
|
@ -340,8 +340,17 @@ 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 = PyDict_SetItemString(type->tp_dict,
|
||||
"__abstractmethods__", value);
|
||||
int res;
|
||||
if (value != NULL) {
|
||||
res = PyDict_SetItemString(type->tp_dict, "__abstractmethods__", value);
|
||||
}
|
||||
else {
|
||||
res = PyDict_DelItemString(type->tp_dict, "__abstractmethods__");
|
||||
if (res && PyErr_ExceptionMatches(PyExc_KeyError)) {
|
||||
PyErr_Format(PyExc_AttributeError, "__abstractmethods__", value);
|
||||
return -1;
|
||||
}
|
||||
}
|
||||
if (res == 0) {
|
||||
PyType_Modified(type);
|
||||
if (value && PyObject_IsTrue(value)) {
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue