[Python-checkins] CVS: python/dist/src/Objects classobject.c,2.121,2.122

Barry Warsaw bwarsaw@users.sourceforge.net
Mon, 26 Feb 2001 10:09:17 -0800


Update of /cvsroot/python/python/dist/src/Objects
In directory usw-pr-cvs1:/tmp/cvs-serv25176

Modified Files:
	classobject.c 
Log Message:
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.


Index: classobject.c
===================================================================
RCS file: /cvsroot/python/python/dist/src/Objects/classobject.c,v
retrieving revision 2.121
retrieving revision 2.122
diff -C2 -r2.121 -r2.122
*** classobject.c	2001/02/01 05:27:45	2.121
--- classobject.c	2001/02/26 18:09:15	2.122
***************
*** 1867,1885 ****
  	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);
  }
   
--- 1867,1872 ----
  	char *sname = PyString_AsString(name);
  
! 	PyErr_Format(PyExc_TypeError, "read-only attribute: %s", sname);
! 	return -1;
  }