]> granicus.if.org Git - python/commitdiff
instancemethod_setattro(): Raise TypeError if an attempt is made to
authorBarry Warsaw <barry@python.org>
Mon, 26 Feb 2001 18:09:15 +0000 (18:09 +0000)
committerBarry Warsaw <barry@python.org>
Mon, 26 Feb 2001 18:09:15 +0000 (18:09 +0000)
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.

Objects/classobject.c

index bb17df174a0756af485dc67874fb83f54383d43d..9cca19f832a9dd1d89a48e5e8512cda859d7cb69 100644 (file)
@@ -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;
 }