summaryrefslogtreecommitdiffstats
path: root/Python/ast.c
diff options
context:
space:
mode:
authorBenjamin Peterson <benjamin@python.org>2009-07-20 20:28:08 (GMT)
committerBenjamin Peterson <benjamin@python.org>2009-07-20 20:28:08 (GMT)
commit4879c907ce32655e76c74aee9f49e4be99b862af (patch)
tree16dda3717a5358bd000a44e9a17a6bfb6e60d4c1 /Python/ast.c
parenta2514f4ce9b8333659aae057b3e9f38147151b54 (diff)
downloadcpython-4879c907ce32655e76c74aee9f49e4be99b862af.zip
cpython-4879c907ce32655e76c74aee9f49e4be99b862af.tar.gz
cpython-4879c907ce32655e76c74aee9f49e4be99b862af.tar.bz2
the Slice in x[::] has to have step as None to help the interpreter
Diffstat (limited to 'Python/ast.c')
-rw-r--r--Python/ast.c16
1 files changed, 15 insertions, 1 deletions
diff --git a/Python/ast.c b/Python/ast.c
index 6ccd02f..0644da8 100644
--- a/Python/ast.c
+++ b/Python/ast.c
@@ -1471,7 +1471,21 @@ ast_for_slice(struct compiling *c, const node *n)
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);