diff options
author | Barry Warsaw <barry@python.org> | 2001-02-26 18:09:15 (GMT) |
---|---|---|
committer | Barry Warsaw <barry@python.org> | 2001-02-26 18:09:15 (GMT) |
commit | 4f9b13bac8335d4614499673a3349b2c97401f12 (patch) | |
tree | 131ca9bfc62f72f2768b1b5ed8ea9a77deb00397 /Objects/classobject.c | |
parent | c1e100f2154810c173bc53015e0b9eabbce56555 (diff) | |
download | cpython-4f9b13bac8335d4614499673a3349b2c97401f12.zip cpython-4f9b13bac8335d4614499673a3349b2c97401f12.tar.gz cpython-4f9b13bac8335d4614499673a3349b2c97401f12.tar.bz2 |
instancemethod_setattro(): Raise TypeError if an attempt is made to
set a function attribute on a method (either bound or unbound). This
reverts to Python 2.0 behavior that no attributes of the method are
writable, but provides a more informative error message.
Diffstat (limited to 'Objects/classobject.c')
-rw-r--r-- | Objects/classobject.c | 17 |
1 files changed, 2 insertions, 15 deletions
diff --git a/Objects/classobject.c b/Objects/classobject.c index bb17df1..9cca19f 100644 --- a/Objects/classobject.c +++ b/Objects/classobject.c @@ -1866,21 +1866,8 @@ instancemethod_setattro(register PyMethodObject *im, PyObject *name, { char *sname = PyString_AsString(name); - if (PyEval_GetRestricted() || - strcmp(sname, "im_func") == 0 || - strcmp(sname, "im_self") == 0 || - strcmp(sname, "im_class") == 0) - { - PyErr_Format(PyExc_TypeError, "read-only attribute: %s", - sname); - return -1; - } - if (im->im_self != NULL) { - PyErr_Format(PyExc_TypeError, - "cannot set attributes through bound methods"); - return -1; - } - return PyObject_SetAttr(im->im_func, name, v); + PyErr_Format(PyExc_TypeError, "read-only attribute: %s", sname); + return -1; } |