[Python-checkins] r87956 - in python/branches/release27-maint: Lib/test/test_abc.py Lib/test/test_descr.py Misc/NEWS Objects/typeobject.c

benjamin.peterson python-checkins at python.org
Wed Jan 12 16:49:47 CET 2011


Author: benjamin.peterson
Date: Wed Jan 12 16:49:47 2011
New Revision: 87956

Log:
Merged revisions 87952-87954 via svnmerge from 
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
........


Modified:
   python/branches/release27-maint/   (props changed)
   python/branches/release27-maint/Lib/test/test_abc.py
   python/branches/release27-maint/Lib/test/test_descr.py
   python/branches/release27-maint/Misc/NEWS
   python/branches/release27-maint/Objects/typeobject.c

Modified: python/branches/release27-maint/Lib/test/test_abc.py
==============================================================================
--- python/branches/release27-maint/Lib/test/test_abc.py	(original)
+++ python/branches/release27-maint/Lib/test/test_abc.py	Wed Jan 12 16:49:47 2011
@@ -70,13 +70,6 @@
         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

Modified: python/branches/release27-maint/Lib/test/test_descr.py
==============================================================================
--- python/branches/release27-maint/Lib/test/test_descr.py	(original)
+++ python/branches/release27-maint/Lib/test/test_descr.py	Wed Jan 12 16:49:47 2011
@@ -4553,6 +4553,17 @@
 
         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):

Modified: python/branches/release27-maint/Misc/NEWS
==============================================================================
--- python/branches/release27-maint/Misc/NEWS	(original)
+++ python/branches/release27-maint/Misc/NEWS	Wed Jan 12 16:49:47 2011
@@ -9,6 +9,9 @@
 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.

Modified: python/branches/release27-maint/Objects/typeobject.c
==============================================================================
--- python/branches/release27-maint/Objects/typeobject.c	(original)
+++ python/branches/release27-maint/Objects/typeobject.c	Wed Jan 12 16:49:47 2011
@@ -327,8 +327,17 @@
        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)) {


More information about the Python-checkins mailing list