cpython: ed2511c23dae (original) (raw)
Mercurial > cpython
changeset 71895:ed2511c23dae
make __doc__ mutable on heaptypes (closes #12773) [#12773]
Benjamin Peterson benjamin@python.org | |
---|---|
date | Wed, 17 Aug 2011 12:03:47 -0500 |
parents | 7fee7f9d2c03 |
children | 1a49c98394df |
files | Lib/test/test_descr.py Misc/NEWS Objects/typeobject.c |
diffstat | 3 files changed, 25 insertions(+), 1 deletions(-)[+] [-] Lib/test/test_descr.py 13 Misc/NEWS 2 Objects/typeobject.c 11 |
line wrap: on
line diff
--- a/Lib/test/test_descr.py +++ b/Lib/test/test_descr.py @@ -4261,6 +4261,19 @@ order (MRO) for bases """ m = str(cm.exception) self.assertEqual("'foo' in slots conflicts with class variable", m)
- def test_set_doc(self):
class X:[](#l1.8)
"elephant"[](#l1.9)
X.__doc__ = "banana"[](#l1.10)
self.assertEqual(X.__doc__, "banana")[](#l1.11)
with self.assertRaises(TypeError) as cm:[](#l1.12)
type(list).__dict__["__doc__"].__set__(list, "blah")[](#l1.13)
self.assertIn("can't set list.__doc__", str(cm.exception))[](#l1.14)
with self.assertRaises(TypeError) as cm:[](#l1.15)
type(X).__dict__["__doc__"].__delete__(X)[](#l1.16)
self.assertIn("can't delete X.__doc__", str(cm.exception))[](#l1.17)
self.assertEqual(X.__doc__, "banana")[](#l1.18)
+ class DictProxyTests(unittest.TestCase): def setUp(self): class C(object):
--- a/Misc/NEWS +++ b/Misc/NEWS @@ -10,6 +10,8 @@ What's New in Python 3.3 Alpha 1? Core and Builtins ----------------- +- Issue #12773: Make doc mutable on user-defined classes. +
- Issue #12766: Raise an ValueError when creating a class with a class variable that conflicts with a name in slots.
--- a/Objects/typeobject.c +++ b/Objects/typeobject.c @@ -588,6 +588,15 @@ type_get_doc(PyTypeObject *type, void *c return result; } +static int +type_set_doc(PyTypeObject *type, PyObject *value, void *context) +{
- if (!check_set_special_type_attr(type, value, "doc"))
return -1;[](#l3.11)
- PyType_Modified(type);
- return PyDict_SetItemString(type->tp_dict, "doc", value);
+} + static PyObject * type___instancecheck__(PyObject *type, PyObject *inst) { @@ -623,7 +632,7 @@ static PyGetSetDef type_getsets[] = { {"abstractmethods", (getter)type_abstractmethods, (setter)type_set_abstractmethods, NULL}, {"dict", (getter)type_dict, NULL, NULL},