diff options
author | Jeremy Hylton <jeremy@alum.mit.edu> | 2001-03-22 02:47:58 (GMT) |
---|---|---|
committer | Jeremy Hylton <jeremy@alum.mit.edu> | 2001-03-22 02:47:58 (GMT) |
commit | bc32024769eecd3c2251e00850e6a5c003aa9253 (patch) | |
tree | ac22247a92d89b1952de8defcb42c17f07e24a7b /Python/ceval.c | |
parent | 061d106a0f56c5b4171ad8c56ecfaa6cefb27385 (diff) | |
download | cpython-bc32024769eecd3c2251e00850e6a5c003aa9253.zip cpython-bc32024769eecd3c2251e00850e6a5c003aa9253.tar.gz cpython-bc32024769eecd3c2251e00850e6a5c003aa9253.tar.bz2 |
Extend support for from __future__ import nested_scopes
If a module has a future statement enabling nested scopes, they are
also enable for the exec statement and the functions compile() and
execfile() if they occur in the module.
If Python is run with the -i option, which enters interactive mode
after executing a script, and the script it runs enables nested
scopes, they are also enabled in interactive mode.
XXX The use of -i with -c "from __future__ import nested_scopes" is
not supported. What's the point?
To support these changes, many function variants have been added to
pythonrun.c. All the variants names end with Flags and they take an
extra PyCompilerFlags * argument. It is possible that this complexity
will be eliminated in a future version of the interpreter in which
nested scopes are not optional.
Diffstat (limited to 'Python/ceval.c')
-rw-r--r-- | Python/ceval.c | 18 |
1 files changed, 16 insertions, 2 deletions
diff --git a/Python/ceval.c b/Python/ceval.c index 658ccb2..0905572 100644 --- a/Python/ceval.c +++ b/Python/ceval.c @@ -3456,13 +3456,27 @@ exec_statement(PyFrameObject *f, PyObject *prog, PyObject *globals, else if (PyFile_Check(prog)) { FILE *fp = PyFile_AsFile(prog); char *name = PyString_AsString(PyFile_Name(prog)); - v = PyRun_File(fp, name, Py_file_input, globals, locals); + if (PyEval_GetNestedScopes()) { + PyCompilerFlags cf; + cf.cf_nested_scopes = 1; + v = PyRun_FileFlags(fp, name, Py_file_input, globals, + locals, &cf); + } else { + v = PyRun_File(fp, name, Py_file_input, globals, + locals); + } } else { char *str; if (PyString_AsStringAndSize(prog, &str, NULL)) return -1; - v = PyRun_String(str, Py_file_input, globals, locals); + if (PyEval_GetNestedScopes()) { + PyCompilerFlags cf; + cf.cf_nested_scopes = 1; + v = PyRun_StringFlags(str, Py_file_input, globals, + locals, &cf); + } else + v = PyRun_String(str, Py_file_input, globals, locals); } if (plain) PyFrame_LocalsToFast(f, 0); |