summaryrefslogtreecommitdiff
path: root/Objects/typeobject.c
diff options
context:
space:
mode:
Diffstat (limited to 'Objects/typeobject.c')
-rw-r--r--Objects/typeobject.c13
1 files changed, 11 insertions, 2 deletions
diff --git a/Objects/typeobject.c b/Objects/typeobject.c
index 7a11796765..84a755a181 100644
--- a/Objects/typeobject.c
+++ b/Objects/typeobject.c
@@ -327,8 +327,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)) {