]> granicus.if.org Git - python/commitdiff
Fix SF bug #1458903 with AST compiler.
authorNeal Norwitz <nnorwitz@gmail.com>
Mon, 27 Mar 2006 08:58:23 +0000 (08:58 +0000)
committerNeal Norwitz <nnorwitz@gmail.com>
Mon, 27 Mar 2006 08:58:23 +0000 (08:58 +0000)
def foo((x)): was getting recognized as requiring tuple unpacking
which is not correct.

Add tests for this case and the proper way to unpack a tuple of one:
def foo((x,)):

test_inpsect was incorrect before.  I'm not sure why it was passing,
but that has been corrected with a test for both functions above.
This means the test (and therefore inspect.getargspec()) are broken in 2.4.

Lib/test/test_grammar.py
Lib/test/test_inspect.py
Python/ast.c

index 5b20ab3d06c143ab2a23a3905c97aa38d0191a81..45e3c49cf9e0c73bd64f74e3905e42da75d04e3c 100644 (file)
@@ -255,6 +255,10 @@ d22v(1, 2, 3, 4, 5)
 d22v(*(1, 2, 3, 4))
 d22v(1, 2, *(3, 4, 5))
 d22v(1, *(2, 3), **{'d': 4})
+def d31v((x)): pass
+d31v(1)
+def d32v((x,)): pass
+d32v((1,))
 
 ### lambdef: 'lambda' [varargslist] ':' test
 print 'lambdef'
index ce346b9b211f0077d52a55dda60288ac4f89d51a..79be3694ab14d3ebc7b0fed192d2578f0f6e8c18 100644 (file)
@@ -304,10 +304,12 @@ class TestClassesAndFunctions(unittest.TestCase):
         self.assertArgSpecEquals(A.m, ['self'])
 
     def test_getargspec_sublistofone(self):
-        def sublistOfOne((foo)): return 1
-
+        def sublistOfOne((foo,)): return 1
         self.assertArgSpecEquals(sublistOfOne, [['foo']])
 
+        def fakeSublistOfOne((foo)): return 1
+        self.assertArgSpecEquals(fakeSublistOfOne, ['foo'])
+
     def test_classify_oldstyle(self):
         class A:
             def s(): pass
index 30275a6d403d476e8c5b541b26e26fb85ab0d3b9..86f3d3c7c69b8a0c70fb14b28e5e12ac8c3dd629 100644 (file)
@@ -645,10 +645,17 @@ ast_for_arguments(struct compiling *c, const node *n)
                    goto error;
                }
                 if (NCH(ch) == 3) {
-                    asdl_seq_SET(args, k++, 
-                                    compiler_complex_args(c, CHILD(ch, 1))); 
-               }
-                else if (TYPE(CHILD(ch, 0)) == NAME) {
+                   ch = CHILD(ch, 1);
+                   /* def foo((x)): is not complex, special case. */
+                   if (NCH(ch) != 1) {
+                       /* We have complex arguments, setup for unpacking. */
+                       asdl_seq_SET(args, k++, compiler_complex_args(c, ch));
+                   } else {
+                       /* def foo((x)): setup for checking NAME below. */
+                       ch = CHILD(ch, 0);
+                   }
+                }
+                if (TYPE(CHILD(ch, 0)) == NAME) {
                    expr_ty name;
                    if (!strcmp(STR(CHILD(ch, 0)), "None")) {
                            ast_error(CHILD(ch, 0), "assignment to None");