[Python-checkins] r53728 - sandbox/trunk/2to3/fixes/fix_dict2.py
guido.van.rossum
python-checkins at python.org
Sun Feb 11 00:52:29 CET 2007
Author: guido.van.rossum
Date: Sun Feb 11 00:52:29 2007
New Revision: 53728
Added:
sandbox/trunk/2to3/fixes/fix_dict2.py (contents, props changed)
Log:
Add a much simpler dict refactorer, which is less safe but more practical.
Added: sandbox/trunk/2to3/fixes/fix_dict2.py
==============================================================================
--- (empty file)
+++ sandbox/trunk/2to3/fixes/fix_dict2.py Sun Feb 11 00:52:29 2007
@@ -0,0 +1,36 @@
+# Copyright 2007 Google, Inc. All Rights Reserved.
+
+"""Fixer for dict methods, take 2.
+
+This is less correct but more pragmatic.
+
+.iterkeys -> .keys
+.iteritems -> .items
+.itervalues -> .values
+"""
+
+# Python imports
+import token
+
+# Local imports
+import pytree
+from fixes import basefix
+from fixes import macros
+
+class FixDict2(basefix.BaseFix):
+
+ PATTERN = """
+ trailer< '.' method=('iterkeys'|'iteritems'|'itervalues') >
+ """
+
+ def transform(self, node):
+ results = self.match(node)
+ method = results["method"][0].value # Extract method name
+ assert method.startswith("iter")
+ newmethod = method[4:]
+ new = pytree.Node(self.syms.trailer,
+ [pytree.Leaf(token.DOT, '.'),
+ macros.Name(newmethod)])
+ new.set_prefix(node.get_prefix())
+ new.children[1].set_prefix(node.children[1].get_prefix())
+ return new
More information about the Python-checkins
mailing list