]> granicus.if.org Git - python/commitdiff
keep the slice.step field as NULL if no step expression is given
authorBenjamin Peterson <benjamin@python.org>
Sat, 13 Jun 2009 01:40:00 +0000 (01:40 +0000)
committerBenjamin Peterson <benjamin@python.org>
Sat, 13 Jun 2009 01:40:00 +0000 (01:40 +0000)
Lib/test/test_ast.py
Misc/NEWS
Python/ast.c

index 1674b9757555f61afa2d4062f635986bb330e4f2..eac42d3feb4a1c044ab17ee583ee489b95f23bc8 100644 (file)
@@ -146,6 +146,12 @@ class AST_Tests(unittest.TestCase):
                 self.assertEquals(to_tuple(ast_tree), o)
                 self._assert_order(ast_tree, (0, 0))
 
+    def test_slice(self):
+        slc = ast.parse("x[::]").body[0].value.slice
+        self.assertIsNone(slc.upper)
+        self.assertIsNone(slc.lower)
+        self.assertIsNone(slc.step)
+
     def test_nodeclasses(self):
         x = ast.BinOp(1, 2, 3, lineno=0)
         self.assertEquals(x.left, 1)
index 3a4e1ac370070488f32d7b14ce674df0208a9f28..11926185d638338d7be9db1a0a6bd1106ad6ed02 100644 (file)
--- a/Misc/NEWS
+++ b/Misc/NEWS
@@ -12,6 +12,9 @@ What's New in Python 2.7 alpha 1
 Core and Builtins
 -----------------
 
+- In the slice AST type, the step field will always be None if a step expression
+  is not specified.
+
 - Issue #4547: When debugging a very large function, it was not always
   possible to update the lineno attribute of the current frame.
 
index b3f4fcb6c08748c519f1406b7f02e4e0c5c82e1c..772047fc4b069a5fd93ccd4039c8590fe85b32b7 100644 (file)
@@ -1468,14 +1468,7 @@ ast_for_slice(struct compiling *c, const node *n)
 
     ch = CHILD(n, NCH(n) - 1);
     if (TYPE(ch) == sliceop) {
-        if (NCH(ch) == 1) {
-            /* No expression, so step is None */
-            ch = CHILD(ch, 0);
-            step = Name(new_identifier("None", c->c_arena), Load,
-                        LINENO(ch), ch->n_col_offset, c->c_arena);
-            if (!step)
-                return NULL;
-        } else {
+        if (NCH(ch) != 1) {
             ch = CHILD(ch, 1);
             if (TYPE(ch) == test) {
                 step = ast_for_expr(c, ch);