[Python-checkins] r57999 - in sandbox/trunk/2to3: fixes/fix_filter.py fixes/fix_map.py tests/test_fixers.py
collin.winter
python-checkins at python.org
Thu Sep 6 07:13:04 CEST 2007
Author: collin.winter
Date: Thu Sep 6 07:13:04 2007
New Revision: 57999
Modified:
sandbox/trunk/2to3/fixes/fix_filter.py
sandbox/trunk/2to3/fixes/fix_map.py
sandbox/trunk/2to3/tests/test_fixers.py
Log:
Slightly extend the set of lambda statements that fix_map and fix_filter can convert into listcomps.
Modified: sandbox/trunk/2to3/fixes/fix_filter.py
==============================================================================
--- sandbox/trunk/2to3/fixes/fix_filter.py (original)
+++ sandbox/trunk/2to3/fixes/fix_filter.py Thu Sep 6 07:13:04 2007
@@ -28,7 +28,9 @@
trailer<
'('
arglist<
- lambdef< 'lambda' fp=NAME ':' xp=any >
+ lambdef< 'lambda'
+ (fp=NAME | vfpdef< '(' fp=NAME ')'> ) ':' xp=any
+ >
','
it=any
>
Modified: sandbox/trunk/2to3/fixes/fix_map.py
==============================================================================
--- sandbox/trunk/2to3/fixes/fix_map.py (original)
+++ sandbox/trunk/2to3/fixes/fix_map.py Thu Sep 6 07:13:04 2007
@@ -38,7 +38,9 @@
trailer<
'('
arglist<
- lambdef< 'lambda' fp=NAME ':' xp=any >
+ lambdef< 'lambda'
+ (fp=NAME | vfpdef< '(' fp=NAME ')'> ) ':' xp=any
+ >
','
it=any
>
Modified: sandbox/trunk/2to3/tests/test_fixers.py
==============================================================================
--- sandbox/trunk/2to3/tests/test_fixers.py (original)
+++ sandbox/trunk/2to3/tests/test_fixers.py Thu Sep 6 07:13:04 2007
@@ -2209,6 +2209,11 @@
a = """x = [x for x in range(10) if x%2 == 0]"""
self.check(b, a)
+ # Note the parens around x
+ b = """x = filter(lambda (x): x%2 == 0, range(10))"""
+ a = """x = [x for x in range(10) if x%2 == 0]"""
+ self.check(b, a)
+
# XXX This (rare) case is not supported
## b = """x = filter(f, 'abc')[0]"""
## a = """x = list(filter(f, 'abc'))[0]"""
@@ -2284,6 +2289,11 @@
a = """x = [x+1 for x in range(4)]"""
self.check(b, a)
+ # Note the parens around x
+ b = """x = map(lambda (x): x+1, range(4))"""
+ a = """x = [x+1 for x in range(4)]"""
+ self.check(b, a)
+
b = """
foo()
# foo
More information about the Python-checkins
mailing list