diff Python/ast.c @ 37235:9d8b33aff60c legacy-trunk

Fix SF bug #1458903 with AST compiler. 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.
author Neal Norwitz <nnorwitz@gmail.com>
date Mon, 27 Mar 2006 08:58:23 +0000
parents b4d92ef2f338
children 16a64e394602
line wrap: on
line diff
--- a/Python/ast.c	Mon Mar 27 08:43:11 2006 +0000
+++ b/Python/ast.c	Mon Mar 27 08:58:23 2006 +0000
@@ -645,10 +645,17 @@
 		    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");