[Python-checkins] r73404 - in python/trunk: Lib/test/test_ast.py Misc/NEWS Python/ast.c

benjamin.peterson python-checkins at python.org
Sat Jun 13 03:40:00 CEST 2009


Author: benjamin.peterson
Date: Sat Jun 13 03:40:00 2009
New Revision: 73404
Log:
keep the slice.step field as NULL if no step expression is given
Modified:
 python/trunk/Lib/test/test_ast.py
 python/trunk/Misc/NEWS
 python/trunk/Python/ast.c
Modified: python/trunk/Lib/test/test_ast.py
==============================================================================
--- python/trunk/Lib/test/test_ast.py	(original)
+++ python/trunk/Lib/test/test_ast.py	Sat Jun 13 03:40:00 2009
@@ -146,6 +146,12 @@
 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)
Modified: python/trunk/Misc/NEWS
==============================================================================
--- python/trunk/Misc/NEWS	(original)
+++ python/trunk/Misc/NEWS	Sat Jun 13 03:40:00 2009
@@ -12,6 +12,9 @@
 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.
 
Modified: python/trunk/Python/ast.c
==============================================================================
--- python/trunk/Python/ast.c	(original)
+++ python/trunk/Python/ast.c	Sat Jun 13 03:40:00 2009
@@ -1468,14 +1468,7 @@
 
 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);


More information about the Python-checkins mailing list

AltStyle によって変換されたページ (->オリジナル) /