summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--Lib/test/test_abc.py7
-rw-r--r--Lib/test/test_descr.py11
-rw-r--r--Misc/NEWS3
-rw-r--r--Objects/typeobject.c13
4 files changed, 25 insertions, 9 deletions
diff --git a/Lib/test/test_abc.py b/Lib/test/test_abc.py
index edd2c047f2..6a8c3a1327 100644
--- a/Lib/test/test_abc.py
+++ b/Lib/test/test_abc.py
@@ -70,13 +70,6 @@ class TestABC(unittest.TestCase):
self.assertFalse(issubclass(OldstyleClass, A))
self.assertFalse(issubclass(A, OldstyleClass))
- def test_type_has_no_abstractmethods(self):
- # type pretends not to have __abstractmethods__.
- self.assertRaises(AttributeError, getattr, type, "__abstractmethods__")
- class meta(type):
- pass
- self.assertRaises(AttributeError, getattr, meta, "__abstractmethods__")
-
def test_isinstance_class(self):
class A:
__metaclass__ = abc.ABCMeta
diff --git a/Lib/test/test_descr.py b/Lib/test/test_descr.py
index 414913dc90..c482cacc2b 100644
--- a/Lib/test/test_descr.py
+++ b/Lib/test/test_descr.py
@@ -4553,6 +4553,17 @@ order (MRO) for bases """
self.assertRaises(AttributeError, getattr, EvilGetattribute(), "attr")
+ def test_abstractmethods(self):
+ # type pretends not to have __abstractmethods__.
+ self.assertRaises(AttributeError, getattr, type, "__abstractmethods__")
+ class meta(type):
+ pass
+ self.assertRaises(AttributeError, getattr, meta, "__abstractmethods__")
+ class X(object):
+ pass
+ with self.assertRaises(AttributeError):
+ del X.__abstractmethods__
+
class DictProxyTests(unittest.TestCase):
def setUp(self):
diff --git a/Misc/NEWS b/Misc/NEWS
index ab47022b80..95e31b944a 100644
--- a/Misc/NEWS
+++ b/Misc/NEWS
@@ -9,6 +9,9 @@ What's New in Python 2.7.2?
Core and Builtins
-----------------
+- Issue #10892: Don't segfault when trying to delete __abstractmethods__ from a
+ class.
+
- Issue #8020: Avoid a crash where the small objects allocator would read
non-Python managed memory while it is being modified by another thread.
Patch by Matt Bandy.
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)) {