support exec(cmd,g) as alternative signature for exec(cmd,g,l) in -3 mode
authorStefan Behnel <scoder@users.berlios.de>
Wed, 3 Nov 2010 19:20:06 +0000 (20:20 +0100)
committerStefan Behnel <scoder@users.berlios.de>
Wed, 3 Nov 2010 19:20:06 +0000 (20:20 +0100)
Cython/Compiler/Builtin.py
Cython/Compiler/Scanning.py
tests/run/cython3.pyx

index b88dba9b914d5d2e6eb58910bbbf5a6f261c0d5e..f7b598066401f65e48b5befde44d2ce0198d7ed8 100644 (file)
@@ -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;
index 44a27315932dd6cfcae935db2a7ef6f713775fd7..1f60f703464fd55c5f9499e5ab07fc0d67f264aa 100644 (file)
@@ -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
index 8c79cec6ad7f6febbfde921156c8924ac4fb8843..b197eb35c0dd2bbe22f299427dec4cf55d2b9ff8 100644 (file)
@@ -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():