From: Michael W. Hudson Date: Thu, 17 Feb 2005 10:43:12 +0000 (+0000) Subject: Backport: Fix X-Git-Tag: v2.4.1c1~44 X-Git-Url: http://git.ipfire.org/gitweb.cgi?a=commitdiff_plain;h=8ed7e2e2db9161379f001e010d5de5d775e397b9;p=thirdparty%2FPython%2Fcpython.git Backport: Fix [ 1124295 ] Function's __name__ no longer accessible in restricted mode which I introduced with a bit of mindless copy-paste when making __name__ writable. You can't assign to __name__ in restricted mode, which I'm going to pretend was intentional :) --- diff --git a/Lib/test/test_funcattrs.py b/Lib/test/test_funcattrs.py index 1acfeb5e65ba..7a083b70dfbf 100644 --- a/Lib/test/test_funcattrs.py +++ b/Lib/test/test_funcattrs.py @@ -276,6 +276,9 @@ def test_func_name(): verify(f.func_name == "h") cantset(f, "func_globals", 1) cantset(f, "__name__", 1) + # test that you can access func.__name__ in restricted mode + s = """def f(): pass\nf.__name__""" + exec s in {'__builtins__':{}} def test_func_code(): diff --git a/Objects/funcobject.c b/Objects/funcobject.c index c7f7c9d23df0..c0c91c95d17d 100644 --- a/Objects/funcobject.c +++ b/Objects/funcobject.c @@ -262,8 +262,6 @@ func_set_code(PyFunctionObject *op, PyObject *value) static PyObject * func_get_name(PyFunctionObject *op) { - if (restricted()) - return NULL; Py_INCREF(op->func_name); return op->func_name; }