[Python-checkins] r57908 - in sandbox/trunk/2to3: fixes/fix_dict.py fixes/fix_filter.py fixes/fix_map.py tests/test_fixers.py
collin.winter
python-checkins at python.org
Sun Sep 2 21:13:28 CEST 2007
Author: collin.winter
Date: Sun Sep 2 21:13:18 2007
New Revision: 57908
Modified:
sandbox/trunk/2to3/fixes/fix_dict.py
sandbox/trunk/2to3/fixes/fix_filter.py
sandbox/trunk/2to3/fixes/fix_map.py
sandbox/trunk/2to3/tests/test_fixers.py
Log:
Add sum() to the list of special contexts for fix_dict, fix_map and fix_filter.
Modified: sandbox/trunk/2to3/fixes/fix_dict.py
==============================================================================
--- sandbox/trunk/2to3/fixes/fix_dict.py (original)
+++ sandbox/trunk/2to3/fixes/fix_dict.py Sun Sep 2 21:13:18 2007
@@ -15,7 +15,7 @@
when the context is list(), sorted(), iter() or for...in; the list()
can be dropped when the context is list() or sorted() (but not iter()
or for...in!). Special contexts that apply to both: list(), sorted(), tuple()
-set(), any(), all().
+set(), any(), all(), sum().
Note: iter(d.keys()) could be written as iter(d) but since the
original d.iterkeys() was also redundant we don't fix this. And there
@@ -31,7 +31,8 @@
from fixes.util import Name, Call, LParen, RParen, ArgList, Dot, set
-exempt = set(["sorted", "list", "set", "any", "all", "tuple"])
+exempt = set(["sorted", "list", "set", "any", "all", "tuple", "sum"])
+iter_exempt = exempt | set(["iter"])
class FixDict(basefix.BaseFix):
@@ -88,7 +89,7 @@
results["node"] is node):
if isiter:
# iter(d.iterkeys()) -> iter(d.keys()), etc.
- return results["func"].value in exempt | set(["iter"])
+ return results["func"].value in iter_exempt
else:
# list(d.keys()) -> list(d.keys()), etc.
return results["func"].value in exempt
Modified: sandbox/trunk/2to3/fixes/fix_filter.py
==============================================================================
--- sandbox/trunk/2to3/fixes/fix_filter.py (original)
+++ sandbox/trunk/2to3/fixes/fix_filter.py Sun Sep 2 21:13:18 2007
@@ -64,7 +64,7 @@
P1 = """
power<
- ( 'iter' | 'list' | 'tuple' | 'sorted' | 'set' |
+ ( 'iter' | 'list' | 'tuple' | 'sorted' | 'set' | 'sum' |
'any' | 'all' | (any* trailer< '.' 'join' >) )
trailer< '(' node=any ')' >
any*
Modified: sandbox/trunk/2to3/fixes/fix_map.py
==============================================================================
--- sandbox/trunk/2to3/fixes/fix_map.py (original)
+++ sandbox/trunk/2to3/fixes/fix_map.py Sun Sep 2 21:13:18 2007
@@ -81,7 +81,7 @@
P1 = """
power<
- ( 'iter' | 'list' | 'tuple' | 'sorted' | 'set' |
+ ( 'iter' | 'list' | 'tuple' | 'sorted' | 'set' | 'sum' |
'any' | 'all' | (any* trailer< '.' 'join' >) )
trailer< '(' node=any ')' >
any*
Modified: sandbox/trunk/2to3/tests/test_fixers.py
==============================================================================
--- sandbox/trunk/2to3/tests/test_fixers.py (original)
+++ sandbox/trunk/2to3/tests/test_fixers.py Sun Sep 2 21:13:18 2007
@@ -1025,7 +1025,7 @@
self.check(b, a)
def test_unchanged(self):
- wrappers = ["set", "sorted", "any", "all", "tuple"]
+ wrappers = ["set", "sorted", "any", "all", "tuple", "sum"]
for wrapper in wrappers:
s = "s = %s(d.keys())" % wrapper
self.unchanged(s)
@@ -2240,6 +2240,8 @@
self.unchanged(a)
a = """all(filter(f, 'abc'))"""
self.unchanged(a)
+ a = """sum(filter(f, 'abc'))"""
+ self.unchanged(a)
a = """sorted(filter(f, 'abc'))"""
self.unchanged(a)
a = """sorted(filter(f, 'abc'), key=blah)"""
@@ -2325,6 +2327,8 @@
self.unchanged(a)
a = """all(map(f, 'abc'))"""
self.unchanged(a)
+ a = """sum(map(f, 'abc'))"""
+ self.unchanged(a)
a = """sorted(map(f, 'abc'))"""
self.unchanged(a)
a = """sorted(map(f, 'abc'), key=blah)"""
More information about the Python-checkins
mailing list