]> git.ipfire.org Git - thirdparty/Python/cpython.git/commitdiff
Merged revisions 85154 via svnmerge from
authorBenjamin Peterson <benjamin@python.org>
Sat, 2 Oct 2010 00:08:58 +0000 (00:08 +0000)
committerBenjamin Peterson <benjamin@python.org>
Sat, 2 Oct 2010 00:08:58 +0000 (00:08 +0000)
svn+ssh://pythondev@svn.python.org/python/branches/py3k

........
  r85154 | benjamin.peterson | 2010-10-01 19:03:31 -0500 (Fri, 01 Oct 2010) | 1 line

  type.__abstractmethods__ should raise an AttributeError #10006
........

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

index 6a8c3a132742720c0bb1aef35ecbecb79f30f18d..edd2c047f222196f4bb9e1afa398208338701a51 100644 (file)
@@ -70,6 +70,13 @@ 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
index 1fabf61501b2c5d458b3bcc4311bec10ab68e29e..94c0ff72d7d3f352df22175496d5b63100d1873b 100644 (file)
--- a/Misc/NEWS
+++ b/Misc/NEWS
@@ -17,6 +17,8 @@ Core and Builtins
   fixes an interpreter crash when initializing an instance of a long
   subclass from an object whose __long__ method returns a plain int.
 
+- Issue #10006: type.__abstractmethods__ now raises an AttributeError.
+
 - Issue #9797: pystate.c wrongly assumed that zero couldn't be a valid
   thread-local storage key.
 
index d26216812037ac128abfae04796ae0ad2108d143..9cb7e6238e169bf410ab1a945eb794c4585bc1f6 100644 (file)
@@ -307,8 +307,11 @@ type_set_module(PyTypeObject *type, PyObject *value, void *context)
 static PyObject *
 type_abstractmethods(PyTypeObject *type, void *context)
 {
-    PyObject *mod = PyDict_GetItemString(type->tp_dict,
-                                         "__abstractmethods__");
+    PyObject *mod = NULL;
+    /* type its self has an __abstractmethods__ descriptor (this). Don't
+       return that. */
+    if (type != &PyType_Type)
+        mod = PyDict_GetItemString(type->tp_dict, "__abstractmethods__");
     if (!mod) {
         PyErr_Format(PyExc_AttributeError, "__abstractmethods__");
         return NULL;