[Python-checkins] r85154 - in python/branches/py3k: Lib/test/test_abc.py Misc/NEWS Objects/typeobject.c
benjamin.peterson
python-checkins at python.org
Sat Oct 2 02:03:31 CEST 2010
Author: benjamin.peterson
Date: Sat Oct 2 02:03:31 2010
New Revision: 85154
Log:
type.__abstractmethods__ should raise an AttributeError #10006
Modified:
python/branches/py3k/Lib/test/test_abc.py
python/branches/py3k/Misc/NEWS
python/branches/py3k/Objects/typeobject.c
Modified: python/branches/py3k/Lib/test/test_abc.py
==============================================================================
--- python/branches/py3k/Lib/test/test_abc.py (original)
+++ python/branches/py3k/Lib/test/test_abc.py Sat Oct 2 02:03:31 2010
@@ -98,6 +98,13 @@
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
Modified: python/branches/py3k/Misc/NEWS
==============================================================================
--- python/branches/py3k/Misc/NEWS (original)
+++ python/branches/py3k/Misc/NEWS Sat Oct 2 02:03:31 2010
@@ -10,6 +10,8 @@
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.
Modified: python/branches/py3k/Objects/typeobject.c
==============================================================================
--- python/branches/py3k/Objects/typeobject.c (original)
+++ python/branches/py3k/Objects/typeobject.c Sat Oct 2 02:03:31 2010
@@ -320,8 +320,11 @@
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;
More information about the Python-checkins
mailing list