diff Objects/classobject.c @ 16767:b6a52e438344 legacy-trunk

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.
author Barry Warsaw <barry@python.org>
date Mon, 26 Feb 2001 18:09:15 +0000
parents 1fb6672b20ef
children d446e4ec9b7b
line wrap: on
line diff
--- a/Objects/classobject.c	Mon Feb 26 18:07:26 2001 +0000
+++ b/Objects/classobject.c	Mon Feb 26 18:09:15 2001 +0000
@@ -1866,21 +1866,8 @@
 {
 	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;
 }