]> git.ipfire.org Git - thirdparty/Python/cpython.git/commitdiff
type.__abstractmethods__ should raise an AttributeError #10006
authorBenjamin Peterson <benjamin@python.org>
Sat, 2 Oct 2010 00:03:31 +0000 (00:03 +0000)
committerBenjamin Peterson <benjamin@python.org>
Sat, 2 Oct 2010 00:03:31 +0000 (00:03 +0000)
Lib/test/test_abc.py
Misc/NEWS
Objects/typeobject.c

index bc095069a8089f3f35e78f63b070c43dce6d5e50..3a1d76b903417bf981e6609c07fc93cb7228236e 100644 (file)
@@ -98,6 +98,13 @@ 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_registration_basics(self):
         class A(metaclass=abc.ABCMeta):
             pass
index 3aa6a6d43a4a427ff91d2773afed5086cd3ca5ca..1d943b06892159623ac0aa9580b6187eaefe1e93 100644 (file)
--- a/Misc/NEWS
+++ b/Misc/NEWS
@@ -10,6 +10,8 @@ What's New in Python 3.2 Alpha 3?
 Core and Builtins
 -----------------
 
+- Issue #10006: type.__abstractmethods__ now raises an AttributeError.
+
 - Issue #10003: Allow handling of SIGBREAK on Windows. Fixes a regression
   introduced by issue #9324. 
 
index 7bdcb1233cf8567843a4e019a3ed481527f4e7c4..c8c198df3f0504f9b66191e1b0062c02ce861fda 100644 (file)
@@ -320,8 +320,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;