]> granicus.if.org Git - python/commitdiff
Issue#2238: some syntax errors from *args or **kwargs expressions
authorAmaury Forgeot d'Arc <amauryfa@gmail.com>
Wed, 5 Mar 2008 01:50:33 +0000 (01:50 +0000)
committerAmaury Forgeot d'Arc <amauryfa@gmail.com>
Wed, 5 Mar 2008 01:50:33 +0000 (01:50 +0000)
would give bogus error messages, because of untested exceptions::

    >>> f(**g(1=2))
    XXX undetected error
    Traceback (most recent call last):
      File "<stdin>", line 1, in <module>
    TypeError: 'int' object is not iterable

instead of the expected SyntaxError: keyword can't be an expression

Will backport.

Lib/test/test_grammar.py
Misc/NEWS
Python/ast.c

index e2bb3eb9e630dbeed338ad5accb0397cdaf11222..0e593677fd50d249452d9dfaa1509a8876807d5b 100644 (file)
@@ -282,6 +282,10 @@ class GrammarTests(unittest.TestCase):
         def d32v((x,)): pass
         d32v((1,))
 
+        # Check ast errors in *args and *kwargs
+        check_syntax_error(self, "f(*g(1=2))")
+        check_syntax_error(self, "f(**g(1=2))")
+
     def testLambdef(self):
         ### lambdef: 'lambda' [varargslist] ':' test
         l1 = lambda : 0
index 4fac8599a6c4004c3bd8827d0f0425aa679af06e..4992513fac6b4e265f211ed70c86b8f8a7de09fa 100644 (file)
--- a/Misc/NEWS
+++ b/Misc/NEWS
@@ -9,6 +9,12 @@ What's New in Python 2.6 alpha 2?
 
 *Release date: XX-XXX-2008*
 
+Core and builtins
+-----------------
+
+- Issue #2238: Some syntax errors in *args and **kwargs expressions could give
+  bogus error messages.
+
 
 What's New in Python 2.6 alpha 1?
 =================================
index 7a1b5bc13e1b7931312cf5d325af4131cbedefe6..e14ff3a3da19a055fd57ccc467fdea36fdfa18bb 100644 (file)
@@ -1934,10 +1934,14 @@ ast_for_call(struct compiling *c, const node *n, expr_ty func)
         }
         else if (TYPE(ch) == STAR) {
             vararg = ast_for_expr(c, CHILD(n, i+1));
+            if (!vararg)
+                return NULL;
             i++;
         }
         else if (TYPE(ch) == DOUBLESTAR) {
             kwarg = ast_for_expr(c, CHILD(n, i+1));
+            if (!kwarg)
+                return NULL;
             i++;
         }
     }