Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit de36871

Browse files
committed
Merged revisions 87952-87954 via svnmerge from
svn+ssh://[email protected]/python/branches/py3k ........ r87952 | benjamin.peterson | 2011-01-12 09:24:27 -0600 (Wed, 12 Jan 2011) | 1 line move this test to test_descr; it's not abc specific ........ r87953 | benjamin.peterson | 2011-01-12 09:25:02 -0600 (Wed, 12 Jan 2011) | 1 line oops, wrong class ........ r87954 | benjamin.peterson | 2011-01-12 09:34:01 -0600 (Wed, 12 Jan 2011) | 1 line don't segfault on deleting __abstractmethods__ #10892 ........
1 parent 6e1d0a8 commit de36871

4 files changed

Lines changed: 25 additions & 9 deletions

File tree

Lib/test/test_abc.py

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -60,13 +60,6 @@ def bar(self): pass # abstract override of concrete
6060
self.assertRaises(TypeError, F) # because bar is abstract now
6161
self.assertTrue(isabstract(F))
6262

63-
def test_type_has_no_abstractmethods(self):
64-
# type pretends not to have __abstractmethods__.
65-
self.assertRaises(AttributeError, getattr, type, "__abstractmethods__")
66-
class meta(type):
67-
pass
68-
self.assertRaises(AttributeError, getattr, meta, "__abstractmethods__")
69-
7063
def test_metaclass_abc(self):
7164
# Metaclasses can be ABCs, too.
7265
class A(metaclass=abc.ABCMeta):

Lib/test/test_descr.py

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4224,6 +4224,17 @@ def __getattribute__(self, name):
42244224

42254225
self.assertRaises(AttributeError, getattr, EvilGetattribute(), "attr")
42264226

4227+
def test_abstractmethods(self):
4228+
# type pretends not to have __abstractmethods__.
4229+
self.assertRaises(AttributeError, getattr, type, "__abstractmethods__")
4230+
class meta(type):
4231+
pass
4232+
self.assertRaises(AttributeError, getattr, meta, "__abstractmethods__")
4233+
class X(object):
4234+
pass
4235+
with self.assertRaises(AttributeError):
4236+
del X.__abstractmethods__
4237+
42274238

42284239
class DictProxyTests(unittest.TestCase):
42294240
def setUp(self):

Misc/NEWS

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,9 @@ What's New in Python 3.1.4?
1010
Core and Builtins
1111
-----------------
1212

13+
- Issue #10892: Don't segfault when trying to delete __abstractmethods__ from a
14+
class.
15+
1316
- Issue #8020: Avoid a crash where the small objects allocator would read
1417
non-Python managed memory while it is being modified by another thread.
1518
Patch by Matt Bandy.

Objects/typeobject.c

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -340,8 +340,17 @@ type_set_abstractmethods(PyTypeObject *type, PyObject *value, void *context)
340340
abc.ABCMeta.__new__, so this function doesn't do anything
341341
special to update subclasses.
342342
*/
343-
int res = PyDict_SetItemString(type->tp_dict,
344-
"__abstractmethods__", value);
343+
int res;
344+
if (value != NULL) {
345+
res = PyDict_SetItemString(type->tp_dict, "__abstractmethods__", value);
346+
}
347+
else {
348+
res = PyDict_DelItemString(type->tp_dict, "__abstractmethods__");
349+
if (res && PyErr_ExceptionMatches(PyExc_KeyError)) {
350+
PyErr_Format(PyExc_AttributeError, "__abstractmethods__", value);
351+
return -1;
352+
}
353+
}
345354
if (res == 0) {
346355
PyType_Modified(type);
347356
if (value && PyObject_IsTrue(value)) {

0 commit comments

Comments
 (0)