mirror of
https://github.com/python/cpython.git
synced 2025-09-26 18:29:57 +00:00
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 :)
This commit is contained in:
parent
5bbe6ad2b5
commit
ee319f66ab
2 changed files with 3 additions and 2 deletions
|
@ -276,6 +276,9 @@ def test_func_name():
|
||||||
verify(f.func_name == "h")
|
verify(f.func_name == "h")
|
||||||
cantset(f, "func_globals", 1)
|
cantset(f, "func_globals", 1)
|
||||||
cantset(f, "__name__", 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():
|
def test_func_code():
|
||||||
|
|
|
@ -262,8 +262,6 @@ func_set_code(PyFunctionObject *op, PyObject *value)
|
||||||
static PyObject *
|
static PyObject *
|
||||||
func_get_name(PyFunctionObject *op)
|
func_get_name(PyFunctionObject *op)
|
||||||
{
|
{
|
||||||
if (restricted())
|
|
||||||
return NULL;
|
|
||||||
Py_INCREF(op->func_name);
|
Py_INCREF(op->func_name);
|
||||||
return op->func_name;
|
return op->func_name;
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue