mirror of
https://github.com/python/cpython.git
synced 2025-11-03 03:22:27 +00:00
type.__abstractmethods__ should raise an AttributeError #10006
This commit is contained in:
parent
ea8676bf8b
commit
aec5fd1397
3 changed files with 14 additions and 2 deletions
|
|
@ -98,6 +98,13 @@ class TestABC(unittest.TestCase):
|
||||||
self.assertRaises(TypeError, F) # because bar is abstract now
|
self.assertRaises(TypeError, F) # because bar is abstract now
|
||||||
self.assertTrue(isabstract(F))
|
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):
|
def test_registration_basics(self):
|
||||||
class A(metaclass=abc.ABCMeta):
|
class A(metaclass=abc.ABCMeta):
|
||||||
pass
|
pass
|
||||||
|
|
|
||||||
|
|
@ -10,6 +10,8 @@ What's New in Python 3.2 Alpha 3?
|
||||||
Core and Builtins
|
Core and Builtins
|
||||||
-----------------
|
-----------------
|
||||||
|
|
||||||
|
- Issue #10006: type.__abstractmethods__ now raises an AttributeError.
|
||||||
|
|
||||||
- Issue #10003: Allow handling of SIGBREAK on Windows. Fixes a regression
|
- Issue #10003: Allow handling of SIGBREAK on Windows. Fixes a regression
|
||||||
introduced by issue #9324.
|
introduced by issue #9324.
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -320,8 +320,11 @@ type_set_module(PyTypeObject *type, PyObject *value, void *context)
|
||||||
static PyObject *
|
static PyObject *
|
||||||
type_abstractmethods(PyTypeObject *type, void *context)
|
type_abstractmethods(PyTypeObject *type, void *context)
|
||||||
{
|
{
|
||||||
PyObject *mod = PyDict_GetItemString(type->tp_dict,
|
PyObject *mod = NULL;
|
||||||
"__abstractmethods__");
|
/* 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) {
|
if (!mod) {
|
||||||
PyErr_Format(PyExc_AttributeError, "__abstractmethods__");
|
PyErr_Format(PyExc_AttributeError, "__abstractmethods__");
|
||||||
return NULL;
|
return NULL;
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue