[Python-checkins] r75734 - in sandbox/trunk/2to3/lib2to3: fixes/fix_map.py tests/test_fixers.py
benjamin.peterson
python-checkins at python.org
Mon Oct 26 22:25:54 CET 2009
Author: benjamin.peterson
Date: Mon Oct 26 22:25:53 2009
New Revision: 75734
Log:
warn on map(None, ...) with more than 2 arguments #7203
Modified:
sandbox/trunk/2to3/lib2to3/fixes/fix_map.py
sandbox/trunk/2to3/lib2to3/tests/test_fixers.py
Modified: sandbox/trunk/2to3/lib2to3/fixes/fix_map.py
==============================================================================
--- sandbox/trunk/2to3/lib2to3/fixes/fix_map.py (original)
+++ sandbox/trunk/2to3/lib2to3/fixes/fix_map.py Mon Oct 26 22:25:53 2009
@@ -50,7 +50,7 @@
|
power<
'map'
- args=trailer< '(' [any] ')' >
+ args=trailer< '(' [arglist=any] ')' >
>
"""
@@ -73,6 +73,14 @@
if "map_none" in results:
new = results["arg"].clone()
else:
+ if "arglist" in results:
+ args = results["arglist"]
+ if args.type == syms.arglist and \
+ args.children[0].type == token.NAME and \
+ args.children[0].value == "None":
+ self.warning(node, "cannot convert map(None, ...) "
+ "with multiple arguments")
+ return
if in_special_context(node):
return None
new = node.clone()
Modified: sandbox/trunk/2to3/lib2to3/tests/test_fixers.py
==============================================================================
--- sandbox/trunk/2to3/lib2to3/tests/test_fixers.py (original)
+++ sandbox/trunk/2to3/lib2to3/tests/test_fixers.py Mon Oct 26 22:25:53 2009
@@ -2834,6 +2834,11 @@
a = """x = list(map(f, 'abc')) # foo"""
self.check(b, a)
+ def test_None_with_multiple_arguments(self):
+ s = """x = map(None, a, b, c)"""
+ self.warns_unchanged(s, "cannot convert map(None, ...) with "
+ "multiple arguments")
+
def test_map_basic(self):
b = """x = map(f, 'abc')"""
a = """x = list(map(f, 'abc'))"""
@@ -2847,10 +2852,6 @@
a = """x = list('abc')"""
self.check(b, a)
- b = """x = map(None, 'abc', 'def')"""
- a = """x = list(map(None, 'abc', 'def'))"""
- self.check(b, a)
-
b = """x = map(lambda x: x+1, range(4))"""
a = """x = [x+1 for x in range(4)]"""
self.check(b, a)
More information about the Python-checkins
mailing list