summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--Lib/test/test_ast.py3
-rw-r--r--Misc/NEWS3
-rw-r--r--Python/ast.c16
3 files changed, 17 insertions, 5 deletions
diff --git a/Lib/test/test_ast.py b/Lib/test/test_ast.py
index 4e311e4473..6dca5d2e65 100644
--- a/Lib/test/test_ast.py
+++ b/Lib/test/test_ast.py
@@ -150,7 +150,8 @@ class AST_Tests(unittest.TestCase):
slc = ast.parse("x[::]").body[0].value.slice
self.assertIsNone(slc.upper)
self.assertIsNone(slc.lower)
- self.assertIsNone(slc.step)
+ self.assertTrue(isinstance(slc.step, ast.Name))
+ self.assertEqual(slc.step.id, "None")
def test_from_import(self):
im = ast.parse("from . import y").body[0]
diff --git a/Misc/NEWS b/Misc/NEWS
index 82c07b4e50..77e3ac6aca 100644
--- a/Misc/NEWS
+++ b/Misc/NEWS
@@ -44,9 +44,6 @@ Core and Builtins
- Assignment to None using import statements now raises a SyntaxError.
-- 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.
diff --git a/Python/ast.c b/Python/ast.c
index 6ccd02fc70..0644da8300 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);