[Python-checkins] r53730 - in sandbox/trunk/2to3: example.py fixes/fix_xrange.py
guido.van.rossum
python-checkins at python.org
Sun Feb 11 01:35:37 CET 2007
Author: guido.van.rossum
Date: Sun Feb 11 01:35:36 2007
New Revision: 53730
Added:
sandbox/trunk/2to3/fixes/fix_xrange.py (contents, props changed)
Modified:
sandbox/trunk/2to3/example.py
Log:
Add a converter that turns xrange() calls into range() calls.
(Still waiting for Neal to implement the new range() :-).
Modified: sandbox/trunk/2to3/example.py
==============================================================================
--- sandbox/trunk/2to3/example.py (original)
+++ sandbox/trunk/2to3/example.py Sun Feb 11 01:35:36 2007
@@ -311,4 +311,9 @@
#
print h.keys()[0]
+def xrange_examples():
+ for i in xrange(100): print i
+ for i in xrange(0, 100): print i
+ for i in xrange(0, 100, 10): print i
+
# This is the last line.
Added: sandbox/trunk/2to3/fixes/fix_xrange.py
==============================================================================
--- (empty file)
+++ sandbox/trunk/2to3/fixes/fix_xrange.py Sun Feb 11 01:35:36 2007
@@ -0,0 +1,28 @@
+# Copyright 2007 Google, Inc. All Rights Reserved.
+
+"""Fixer that changes xrange(...) into range(...)."""
+
+# Python imports
+import token
+
+# Local imports
+import pytree
+from fixes import basefix
+from fixes import macros
+
+class FixXrange(basefix.BaseFix):
+
+ PATTERN = """
+ power<
+ 'xrange'
+ args=trailer< '(' [any] ')' >
+ >
+ """
+
+ def transform(self, node):
+ results = self.match(node)
+ args = results["args"]
+ new = pytree.Node(self.syms.power,
+ [macros.Name("range"), args.clone()])
+ new.set_prefix(node.get_prefix())
+ return new
More information about the Python-checkins
mailing list