[Python-checkins] r56817 - in sandbox/trunk/2to3: fixes/fix_map.py tests/test_fixers.py
collin.winter
python-checkins at python.org
Wed Aug 8 05:58:49 CEST 2007
Author: collin.winter
Date: Wed Aug 8 05:58:49 2007
New Revision: 56817
Modified:
sandbox/trunk/2to3/ (props changed)
sandbox/trunk/2to3/fixes/fix_map.py
sandbox/trunk/2to3/tests/test_fixers.py
Log:
Add a warning to fix_map when map() is found in void context.
Modified: sandbox/trunk/2to3/fixes/fix_map.py
==============================================================================
--- sandbox/trunk/2to3/fixes/fix_map.py (original)
+++ sandbox/trunk/2to3/fixes/fix_map.py Wed Aug 8 05:58:49 2007
@@ -53,7 +53,10 @@
"""
def transform(self, node, results):
- if "map_lambda" in results:
+ if node.parent.type == syms.simple_stmt:
+ self.warning(node, "You should use a for loop here")
+ return
+ elif "map_lambda" in results:
new = ListComp(results.get("xp").clone(),
results.get("fp").clone(),
results.get("it").clone())
Modified: sandbox/trunk/2to3/tests/test_fixers.py
==============================================================================
--- sandbox/trunk/2to3/tests/test_fixers.py (original)
+++ sandbox/trunk/2to3/tests/test_fixers.py Wed Aug 8 05:58:49 2007
@@ -2301,6 +2301,13 @@
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")
+
if __name__ == "__main__":
import __main__
More information about the Python-checkins
mailing list