diff Python/ast.c @ 55362:7bf8fc20037a legacy-trunk

the Slice in x[::] has to have step as None to help the interpreter
author Benjamin Peterson <benjamin@python.org>
date Mon, 20 Jul 2009 20:28:08 +0000
parents 40c8c35492f1
children 1e2877026435
line wrap: on
line diff
--- a/Python/ast.c	Mon Jul 20 17:24:30 2009 +0000
+++ b/Python/ast.c	Mon Jul 20 20:28:08 2009 +0000
@@ -1471,7 +1471,21 @@
 
     ch = CHILD(n, NCH(n) - 1);
     if (TYPE(ch) == sliceop) {
-        if (NCH(ch) != 1) {
+        if (NCH(ch) == 1) {
+            /* 
+              This is an extended slice (ie "x[::]") with no expression in the
+              step field. We set this literally to "None" in order to
+              disambiguate it from x[:]. (The interpreter might have to call
+              __getslice__ for x[:], but it must call __getitem__ for x[::].)
+            */
+            identifier none = new_identifier("None", c->c_arena);
+            if (!none)
+                return NULL;
+            ch = CHILD(ch, 0);
+            step = Name(none, Load, LINENO(ch), ch->n_col_offset, c->c_arena);
+            if (!step)
+                return NULL;
+        } else {
             ch = CHILD(ch, 1);
             if (TYPE(ch) == test) {
                 step = ast_for_expr(c, ch);