diff -r 4fc575d55e2b Lib/lib2to3/fixer_util.py --- a/Lib/lib2to3/fixer_util.py Thu Aug 28 11:19:46 2014 +0200 +++ b/Lib/lib2to3/fixer_util.py Thu Aug 28 13:38:50 2014 +0200 @@ -188,7 +188,8 @@ consuming_calls = set(["sorted", "list", "set", "any", "all", "tuple", "sum", - "min", "max", "enumerate"]) + "min", "max", "enumerate", + "len", "zip", "map", "reduce", "filter", "dict"]) def attr_chain(obj, attr): """Follow an attribute chain. @@ -215,6 +216,7 @@ p1 = """ power< ( 'iter' | 'list' | 'tuple' | 'sorted' | 'set' | 'sum' | + 'min' | 'max' | 'len' | 'any' | 'all' | 'enumerate' | (any* trailer< '.' 'join' >) ) trailer< '(' node=any ')' > any* @@ -222,9 +224,17 @@ """ p2 = """ power< - ( 'sorted' | 'enumerate' ) + ( 'sorted' | 'enumerate' | 'dict') trailer< '(' arglist ')' > any* + | + ( 'map' | 'reduce' | 'filter' ) + trailer< '(' arglist ')' > + any* + | + ( 'zip' ) + trailer< '(' arglist ')' > + any* > """ pats_built = False @@ -243,7 +253,9 @@ patterns = [p0, p1, p2] for pattern, parent in zip(patterns, attr_chain(node, "parent")): results = {} - if pattern.match(parent, results) and results["node"] is node: + if pattern.match(parent, results) and \ + (results.get("node") is node or + node in (results.get("nodes") or [])): return True return False diff -r 4fc575d55e2b Lib/lib2to3/fixes/fix_xrange.py --- a/Lib/lib2to3/fixes/fix_xrange.py Thu Aug 28 11:19:46 2014 +0200 +++ b/Lib/lib2to3/fixes/fix_xrange.py Thu Aug 28 13:38:50 2014 +0200 @@ -41,7 +41,7 @@ def transform_range(self, node, results): if (id(node) not in self.transformed_xranges and - not self.in_special_context(node)): + not self.in_special_context(node) and not in_special_context(node)): range_call = Call(Name("range"), [results["args"].clone()]) # Encase the range call in list(). list_call = Call(Name("list"), [range_call], diff -r 4fc575d55e2b Lib/lib2to3/tests/test_fixers.py --- a/Lib/lib2to3/tests/test_fixers.py Thu Aug 28 11:19:46 2014 +0200 +++ b/Lib/lib2to3/tests/test_fixers.py Thu Aug 28 13:38:50 2014 +0200 @@ -3087,6 +3087,16 @@ self.unchanged(a) a = """(x for x in filter(f, 'abc'))""" self.unchanged(a) + a = """r = dict(zip(s, range(len(s))), **d)""" + self.unchanged(a) + a = """r = len(filter(attrgetter('t'), self.a))""" + self.unchanged(a) + a = """r = min(map(methodcaller('f'), self.a))""" + self.unchanged(a) + a = """max(map(node.id, self.nodes)) + 1 if self.nodes else 0""" + self.unchanged(a) + a = """reduce(set.union, map(f, self.a))""" + self.unchanged(a) def test_future_builtins(self): a = "from future_builtins import spam, filter; filter(f, 'ham')"