diff options
author | Benjamin Peterson <benjamin@python.org> | 2010-10-02 00:03:31 +0000 |
---|---|---|
committer | Benjamin Peterson <benjamin@python.org> | 2010-10-02 00:03:31 +0000 |
commit | aec5fd13979f7fac74a057d7a54c124354a715a2 (patch) | |
tree | 360c95d63deea11da4f3871736b11724273620aa | |
parent | ea8676bf8b09003e29278af25e495050638fda47 (diff) | |
download | cpython-git-aec5fd13979f7fac74a057d7a54c124354a715a2.tar.gz |
type.__abstractmethods__ should raise an AttributeError #10006
-rw-r--r-- | Lib/test/test_abc.py | 7 | ||||
-rw-r--r-- | Misc/NEWS | 2 | ||||
-rw-r--r-- | Objects/typeobject.c | 7 |
3 files changed, 14 insertions, 2 deletions
diff --git a/Lib/test/test_abc.py b/Lib/test/test_abc.py index bc095069a8..3a1d76b903 100644 --- a/Lib/test/test_abc.py +++ b/Lib/test/test_abc.py @@ -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 @@ -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. diff --git a/Objects/typeobject.c b/Objects/typeobject.c index 7bdcb1233c..c8c198df3f 100644 --- a/Objects/typeobject.c +++ b/Objects/typeobject.c @@ -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; |