]> git.ipfire.org Git - thirdparty/Python/cpython.git/commitdiff
Backport: Fix
authorMichael W. Hudson <mwh@python.net>
Thu, 17 Feb 2005 10:43:12 +0000 (10:43 +0000)
committerMichael W. Hudson <mwh@python.net>
Thu, 17 Feb 2005 10:43:12 +0000 (10:43 +0000)
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 :)

Lib/test/test_funcattrs.py
Objects/funcobject.c

index 1acfeb5e65bad684b8962a2dccf06049b8652589..7a083b70dfbf18a7b22c24b7434903f8e0b43a66 100644 (file)
@@ -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():
index c7f7c9d23df0dbd836ff84ae0a87c41122f4736b..c0c91c95d17d8c625886f23cd2fc66eea168aad6 100644 (file)
@@ -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;
 }