Commit 60978085 authored by Stefan Behnel's avatar Stefan Behnel

support exec(cmd,g) as alternative signature for exec(cmd,g,l) in -3 mode

parent cac2cf22
......@@ -18,6 +18,7 @@ builtin_function_table = [
('dir', "O", "O", "PyObject_Dir"),
('divmod', "OO", "O", "PyNumber_Divmod"),
('exec', "OOO", "O", "__Pyx_PyRun"),
('exec', "OO", "O", "__Pyx_PyRun2"),
#('eval', "", "", ""),
#('execfile', "", "", ""),
#('filter', "", "", ""),
......@@ -181,8 +182,13 @@ proto = """
#endif
#endif
static PyObject* __Pyx_PyRun(PyObject*, PyObject*, PyObject*);
static CYTHON_INLINE PyObject* __Pyx_PyRun2(PyObject*, PyObject*);
""",
impl = """
static CYTHON_INLINE PyObject* __Pyx_PyRun2(PyObject* o, PyObject* globals) {
return __Pyx_PyRun(o, globals, NULL);
}
static PyObject* __Pyx_PyRun(PyObject* o, PyObject* globals, PyObject* locals) {
PyObject* result;
PyObject* s = 0;
......
......@@ -358,8 +358,11 @@ class PyrexScanner(Scanner):
self.error("Unrecognized character")
if sy == IDENT:
if systring in self.keywords:
if systring == 'print' and \
print_function in self.context.future_directives:
if systring == 'print' and print_function in self.context.future_directives:
self.keywords.remove('print')
systring = EncodedString(systring)
elif systring == 'exec' and self.context.language_level >= 3:
self.keywords.remove('exec')
systring = EncodedString(systring)
else:
sy = systring
......
......@@ -15,6 +15,25 @@ def print_function(*args):
"""
print(*args) # this isn't valid Py2 syntax
def exec3_function(cmd):
"""
>>> exec3_function('a = 1+1')['a']
2
"""
g = {}
l = {}
exec(cmd, g, l)
return l
def exec2_function(cmd):
"""
>>> exec2_function('a = 1+1')['a']
2
"""
g = {}
exec(cmd, g)
return g
ustring = "abcdefg"
def unicode_literals():
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment