[Python-checkins] r57884 - in sandbox/trunk/2to3: fixes/fix_map.py tests/test_fixers.py

collin.winter python-checkins at python.org
Sat Sep 1 22:19:37 CEST 2007


Author: collin.winter
Date: Sat Sep  1 22:19:36 2007
New Revision: 57884

Modified:
   sandbox/trunk/2to3/   (props changed)
   sandbox/trunk/2to3/fixes/fix_map.py
   sandbox/trunk/2to3/tests/test_fixers.py
Log:
Actually fix maps in void context rather than just warning about them.


Modified: sandbox/trunk/2to3/fixes/fix_map.py
==============================================================================
--- sandbox/trunk/2to3/fixes/fix_map.py	(original)
+++ sandbox/trunk/2to3/fixes/fix_map.py	Sat Sep  1 22:19:36 2007
@@ -55,7 +55,9 @@
     def transform(self, node, results):
         if node.parent.type == syms.simple_stmt:
             self.warning(node, "You should use a for loop here")
-            return
+            new = node.clone()
+            new.set_prefix("")
+            new = Call(Name("list"), [new])
         elif "map_lambda" in results:
             new = ListComp(results.get("xp").clone(),
                            results.get("fp").clone(),

Modified: sandbox/trunk/2to3/tests/test_fixers.py
==============================================================================
--- sandbox/trunk/2to3/tests/test_fixers.py	(original)
+++ sandbox/trunk/2to3/tests/test_fixers.py	Sat Sep  1 22:19:36 2007
@@ -2270,6 +2270,18 @@
         a = """x = [x+1 for x in range(4)]"""
         self.check(b, a)
 
+        b = """
+            foo()
+            # foo
+            map(f, x)
+            """
+        a = """
+            foo()
+            # foo
+            list(map(f, x))
+            """
+        self.warns(b, a, "You should use a for loop here")
+
         # XXX This (rare) case is not supported
 ##         b = """x = map(f, 'abc')[0]"""
 ##         a = """x = list(map(f, 'abc'))[0]"""
@@ -2307,13 +2319,6 @@
         a = """(x for x in map(f, 'abc'))"""
         self.unchanged(a)
 
-    def test_warn(self):
-        a = """
-            foo()
-            map(f, x)
-            """
-        self.warns_unchanged(a, "You should use a for loop here")
-
 class Test_standarderror(FixerTestCase):
     fixer = "standarderror"
 


More information about the Python-checkins mailing list