Index: Include/Python-ast.h =================================================================== --- Include/Python-ast.h (revision 42949) +++ Include/Python-ast.h (working copy) @@ -1,4 +1,4 @@ -/* File automatically generated by Parser/asdl_c.py */ +/* File automatically generated by Parser\asdl_c.py */ #include "asdl.h" @@ -300,6 +300,7 @@ expr_ty lower; expr_ty upper; expr_ty step; + bool ext; } Slice; struct { @@ -422,7 +423,8 @@ expr_ty Tuple(asdl_seq * elts, expr_context_ty ctx, int lineno, int col_offset, PyArena *arena); slice_ty Ellipsis(PyArena *arena); -slice_ty Slice(expr_ty lower, expr_ty upper, expr_ty step, PyArena *arena); +slice_ty Slice(expr_ty lower, expr_ty upper, expr_ty step, bool ext, PyArena + *arena); slice_ty ExtSlice(asdl_seq * dims, PyArena *arena); slice_ty Index(expr_ty value, PyArena *arena); comprehension_ty comprehension(expr_ty target, expr_ty iter, asdl_seq * ifs, Index: Lib/test/test_ast.py =================================================================== --- Lib/test/test_ast.py (revision 42949) +++ Lib/test/test_ast.py (working copy) @@ -152,7 +152,8 @@ assert to_tuple(ast_tree) == o test_order(ast_tree, (0, 0)) -#### EVERYTHING BELOW IS GENERATED ##### +#### EVERYTHING BELOW IS GENERATED. TO REGENERATE, EXECUTE THIS FILE ##### +#### WITH THE '-g' COMMAND LINE FLAG AND PASTE THE RESULTS. ##### exec_results = [ ('Module', [('FunctionDef', (1, 0), 'f', ('arguments', [], None, None, []), [('Pass', (1, 9))], [])]), ('Module', [('ClassDef', (1, 0), 'C', [], [('Pass', (1, 8))])]), @@ -194,10 +195,10 @@ ('Expression', ('Num', (1, 0), 10L)), ('Expression', ('Str', (1, 0), 'string')), ('Expression', ('Attribute', (1, 0), ('Name', (1, 0), 'a', ('Load',)), 'b', ('Load',))), -('Expression', ('Subscript', (1, 0), ('Name', (1, 0), 'a', ('Load',)), ('Slice', ('Name', (1, 2), 'b', ('Load',)), ('Name', (1, 4), 'c', ('Load',)), None), ('Load',))), +('Expression', ('Subscript', (1, 0), ('Name', (1, 0), 'a', ('Load',)), ('Slice', ('Name', (1, 2), 'b', ('Load',)), ('Name', (1, 4), 'c', ('Load',)), None, False), ('Load',))), ('Expression', ('Name', (1, 0), 'v', ('Load',))), ('Expression', ('List', (1, 0), [('Num', (1, 1), 1), ('Num', (1, 3), 2), ('Num', (1, 5), 3)], ('Load',))), ('Expression', ('Tuple', (1, 0), [('Num', (1, 0), 1), ('Num', (1, 2), 2), ('Num', (1, 4), 3)], ('Load',))), -('Expression', ('Call', (1, 0), ('Attribute', (1, 0), ('Attribute', (1, 0), ('Attribute', (1, 0), ('Name', (1, 0), 'a', ('Load',)), 'b', ('Load',)), 'c', ('Load',)), 'd', ('Load',)), [('Subscript', (1, 8), ('Attribute', (1, 8), ('Name', (1, 8), 'a', ('Load',)), 'b', ('Load',)), ('Slice', ('Num', (1, 12), 1), ('Num', (1, 14), 2), None), ('Load',))], [], None, None)), +('Expression', ('Call', (1, 0), ('Attribute', (1, 0), ('Attribute', (1, 0), ('Attribute', (1, 0), ('Name', (1, 0), 'a', ('Load',)), 'b', ('Load',)), 'c', ('Load',)), 'd', ('Load',)), [('Subscript', (1, 8), ('Attribute', (1, 8), ('Name', (1, 8), 'a', ('Load',)), 'b', ('Load',)), ('Slice', ('Num', (1, 12), 1), ('Num', (1, 14), 2), None, False), ('Load',))], [], None, None)), ] run_tests() Index: Parser/Python.asdl =================================================================== --- Parser/Python.asdl (revision 42949) +++ Parser/Python.asdl (working copy) @@ -82,7 +82,7 @@ expr_context = Load | Store | Del | AugLoad | AugStore | Param - slice = Ellipsis | Slice(expr? lower, expr? upper, expr? step) + slice = Ellipsis | Slice(expr? lower, expr? upper, expr? step, bool ext) | ExtSlice(slice* dims) | Index(expr value) Index: Python/ast.c =================================================================== --- Python/ast.c (revision 42949) +++ Python/ast.c (working copy) @@ -1318,9 +1318,12 @@ ch = CHILD(n, NCH(n) - 1); if (TYPE(ch) == sliceop) { if (NCH(ch) == 1) + { /* XXX: If only 1 child, then should just be a colon. Should we just skip assigning and just get to the return? */ ch = CHILD(ch, 0); + return Slice(lower, upper, step, 1, c->c_arena); + } else ch = CHILD(ch, 1); if (TYPE(ch) == test) { @@ -1330,7 +1333,7 @@ } } - return Slice(lower, upper, step, c->c_arena); + return Slice(lower, upper, step, 0, c->c_arena); } static expr_ty Index: Python/compile.c =================================================================== --- Python/compile.c (revision 42949) +++ Python/compile.c (working copy) @@ -3773,6 +3773,9 @@ if (s->v.Slice.step) { n++; VISIT(c, expr, s->v.Slice.step); + } else if (s->v.Slice.ext) { + n++; + ADDOP_O(c, LOAD_CONST, Py_None, consts); } ADDOP_I(c, BUILD_SLICE, n); return 1; @@ -3860,7 +3863,7 @@ ADDOP_O(c, LOAD_CONST, Py_Ellipsis, consts); break; case Slice_kind: - if (!s->v.Slice.step) + if (!s->v.Slice.step && !s->v.Slice.ext && s->kind == Slice_kind) return compiler_simple_slice(c, s, ctx); if (!compiler_slice(c, s, ctx)) return 0; Index: Python/Python-ast.c =================================================================== --- Python/Python-ast.c (revision 42949) +++ Python/Python-ast.c (working copy) @@ -1,4 +1,4 @@ -/* File automatically generated by Parser/asdl_c.py */ +/* File automatically generated by Parser\asdl_c.py */ #include "Python.h" #include "Python-ast.h" @@ -263,6 +263,7 @@ "lower", "upper", "step", + "ext", }; static PyTypeObject *ExtSlice_type; static char *ExtSlice_fields[]={ @@ -576,7 +577,7 @@ if (!add_attributes(slice_type, NULL, 0)) return 0; Ellipsis_type = make_type("Ellipsis", slice_type, NULL, 0); if (!Ellipsis_type) return 0; - Slice_type = make_type("Slice", slice_type, Slice_fields, 3); + Slice_type = make_type("Slice", slice_type, Slice_fields, 4); if (!Slice_type) return 0; ExtSlice_type = make_type("ExtSlice", slice_type, ExtSlice_fields, 1); if (!ExtSlice_type) return 0; @@ -1767,7 +1768,7 @@ } slice_ty -Slice(expr_ty lower, expr_ty upper, expr_ty step, PyArena *arena) +Slice(expr_ty lower, expr_ty upper, expr_ty step, bool ext, PyArena *arena) { slice_ty p; p = (slice_ty)PyArena_Malloc(arena, sizeof(*p)); @@ -1779,6 +1780,7 @@ p->v.Slice.lower = lower; p->v.Slice.upper = upper; p->v.Slice.step = step; + p->v.Slice.ext = ext; return p; } @@ -2719,6 +2721,11 @@ if (PyObject_SetAttrString(result, "step", value) == -1) goto failed; Py_DECREF(value); + value = ast2obj_bool(o->v.Slice.ext); + if (!value) goto failed; + if (PyObject_SetAttrString(result, "ext", value) == -1) + goto failed; + Py_DECREF(value); break; case ExtSlice_kind: result = PyType_GenericNew(ExtSlice_type, NULL, NULL);