]> granicus.if.org Git - python/commitdiff
Merged revisions 87952-87954 via svnmerge from
authorBenjamin Peterson <benjamin@python.org>
Wed, 12 Jan 2011 15:42:34 +0000 (15:42 +0000)
committerBenjamin Peterson <benjamin@python.org>
Wed, 12 Jan 2011 15:42:34 +0000 (15:42 +0000)
svn+ssh://pythondev@svn.python.org/python/branches/py3k

........
  r87952 | benjamin.peterson | 2011-01-12 09:24:27 -0600 (Wed, 12 Jan 2011) | 1 line

  move this test to test_descr; it's not abc specific
........
  r87953 | benjamin.peterson | 2011-01-12 09:25:02 -0600 (Wed, 12 Jan 2011) | 1 line

  oops, wrong class
........
  r87954 | benjamin.peterson | 2011-01-12 09:34:01 -0600 (Wed, 12 Jan 2011) | 1 line

  don't segfault on deleting __abstractmethods__ #10892
........

Lib/test/test_abc.py
Lib/test/test_descr.py
Misc/NEWS
Objects/typeobject.c

index 0fa40cb430499fc11ec59eaa4116e7294eb4b0de..3aef4a00f22a8d0ae87f6f1670550fec774f1e14 100644 (file)
@@ -60,13 +60,6 @@ class TestABC(unittest.TestCase):
             self.assertRaises(TypeError, F)  # because bar is abstract now
             self.assertTrue(isabstract(F))
 
-    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_metaclass_abc(self):
         # Metaclasses can be ABCs, too.
         class A(metaclass=abc.ABCMeta):
index e1c928f1794cd7d6b03902d9e3bc088918550287..97a4e4b106f2b00afc107cab6f03a38b5d9117f0 100644 (file)
@@ -4224,6 +4224,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):
index 9157eae3060eebe4a2cbd0e1c52cbe96cce01e3e..63883911d1051ee007c07dd4d663fce90a540e29 100644 (file)
--- a/Misc/NEWS
+++ b/Misc/NEWS
@@ -10,6 +10,9 @@ What's New in Python 3.1.4?
 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.
index c28d0363bdf2a3f3394b92e4a0d8a654607dd153..6a325e823c01a4f6debd9790c165a4b7e266c243 100644 (file)
@@ -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)) {