Skip to content

Commit 79f3e85

Browse files
committed
keep the slice.step field as NULL if no step expression is given
1 parent 7bd141b commit 79f3e85

3 files changed

Lines changed: 10 additions & 8 deletions

File tree

Lib/test/test_ast.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -146,6 +146,12 @@ def test_snippets(self):
146146
self.assertEquals(to_tuple(ast_tree), o)
147147
self._assert_order(ast_tree, (0, 0))
148148

149+
def test_slice(self):
150+
slc = ast.parse("x[::]").body[0].value.slice
151+
self.assertIsNone(slc.upper)
152+
self.assertIsNone(slc.lower)
153+
self.assertIsNone(slc.step)
154+
149155
def test_nodeclasses(self):
150156
x = ast.BinOp(1, 2, 3, lineno=0)
151157
self.assertEquals(x.left, 1)

Misc/NEWS

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,9 @@ What's New in Python 2.7 alpha 1
1212
Core and Builtins
1313
-----------------
1414

15+
- In the slice AST type, the step field will always be None if a step expression
16+
is not specified.
17+
1518
- Issue #4547: When debugging a very large function, it was not always
1619
possible to update the lineno attribute of the current frame.
1720

Python/ast.c

Lines changed: 1 addition & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1468,14 +1468,7 @@ ast_for_slice(struct compiling *c, const node *n)
14681468

14691469
ch = CHILD(n, NCH(n) - 1);
14701470
if (TYPE(ch) == sliceop) {
1471-
if (NCH(ch) == 1) {
1472-
/* No expression, so step is None */
1473-
ch = CHILD(ch, 0);
1474-
step = Name(new_identifier("None", c->c_arena), Load,
1475-
LINENO(ch), ch->n_col_offset, c->c_arena);
1476-
if (!step)
1477-
return NULL;
1478-
} else {
1471+
if (NCH(ch) != 1) {
14791472
ch = CHILD(ch, 1);
14801473
if (TYPE(ch) == test) {
14811474
step = ast_for_expr(c, ch);

0 commit comments

Comments
 (0)