Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 4f9b13b

Browse files
committed
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.
1 parent c1e100f commit 4f9b13b

1 file changed

Lines changed: 2 additions & 15 deletions

File tree

Objects/classobject.c

Lines changed: 2 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1866,21 +1866,8 @@ instancemethod_setattro(register PyMethodObject *im, PyObject *name,
18661866
{
18671867
char *sname = PyString_AsString(name);
18681868

1869-
if (PyEval_GetRestricted() ||
1870-
strcmp(sname, "im_func") == 0 ||
1871-
strcmp(sname, "im_self") == 0 ||
1872-
strcmp(sname, "im_class") == 0)
1873-
{
1874-
PyErr_Format(PyExc_TypeError, "read-only attribute: %s",
1875-
sname);
1876-
return -1;
1877-
}
1878-
if (im->im_self != NULL) {
1879-
PyErr_Format(PyExc_TypeError,
1880-
"cannot set attributes through bound methods");
1881-
return -1;
1882-
}
1883-
return PyObject_SetAttr(im->im_func, name, v);
1869+
PyErr_Format(PyExc_TypeError, "read-only attribute: %s", sname);
1870+
return -1;
18841871
}
18851872

18861873

0 commit comments

Comments
 (0)