summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--Lib/test/test_abc.py7
-rw-r--r--Misc/NEWS2
-rw-r--r--Objects/typeobject.c7
3 files changed, 14 insertions, 2 deletions
diff --git a/Lib/test/test_abc.py b/Lib/test/test_abc.py
index 6a8c3a1327..edd2c047f2 100644
--- a/Lib/test/test_abc.py
+++ b/Lib/test/test_abc.py
@@ -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
diff --git a/Misc/NEWS b/Misc/NEWS
index 1fabf61501..94c0ff72d7 100644
--- 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.
diff --git a/Objects/typeobject.c b/Objects/typeobject.c
index d262168120..9cb7e6238e 100644
--- a/Objects/typeobject.c
+++ b/Objects/typeobject.c
@@ -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;