[Python-checkins] cpython (merge 3.3 -> default): merge 3.3 (#16573)
benjamin.peterson
python-checkins at python.org
Thu Nov 29 16:59:07 CET 2012
http://hg.python.org/cpython/rev/ce3f0399ea33
changeset: 80660:ce3f0399ea33
parent: 80653:efedd0f62a7e
parent: 80658:cff7995ca7e8
user: Benjamin Peterson <benjamin at python.org>
date: Thu Nov 29 10:58:43 2012 -0500
summary:
merge 3.3 (#16573)
files:
Lib/lib2to3/fixer_util.py | 12 ++++++------
Lib/lib2to3/tests/test_fixers.py | 12 ++++++++++++
Misc/NEWS | 4 ++++
3 files changed, 22 insertions(+), 6 deletions(-)
diff --git a/Lib/lib2to3/fixer_util.py b/Lib/lib2to3/fixer_util.py
--- a/Lib/lib2to3/fixer_util.py
+++ b/Lib/lib2to3/fixer_util.py
@@ -165,7 +165,7 @@
consuming_calls = set(["sorted", "list", "set", "any", "all", "tuple", "sum",
- "min", "max"])
+ "min", "max", "enumerate"])
def attr_chain(obj, attr):
"""Follow an attribute chain.
@@ -192,14 +192,14 @@
p1 = """
power<
( 'iter' | 'list' | 'tuple' | 'sorted' | 'set' | 'sum' |
- 'any' | 'all' | (any* trailer< '.' 'join' >) )
+ 'any' | 'all' | 'enumerate' | (any* trailer< '.' 'join' >) )
trailer< '(' node=any ')' >
any*
>
"""
p2 = """
power<
- 'sorted'
+ ( 'sorted' | 'enumerate' )
trailer< '(' arglist<node=any any*> ')' >
any*
>
@@ -207,14 +207,14 @@
pats_built = False
def in_special_context(node):
""" Returns true if node is in an environment where all that is required
- of it is being itterable (ie, it doesn't matter if it returns a list
- or an itterator).
+ of it is being iterable (ie, it doesn't matter if it returns a list
+ or an iterator).
See test_map_nochange in test_fixers.py for some examples and tests.
"""
global p0, p1, p2, pats_built
if not pats_built:
+ p0 = patcomp.compile_pattern(p0)
p1 = patcomp.compile_pattern(p1)
- p0 = patcomp.compile_pattern(p0)
p2 = patcomp.compile_pattern(p2)
pats_built = True
patterns = [p0, p1, p2]
diff --git a/Lib/lib2to3/tests/test_fixers.py b/Lib/lib2to3/tests/test_fixers.py
--- a/Lib/lib2to3/tests/test_fixers.py
+++ b/Lib/lib2to3/tests/test_fixers.py
@@ -2981,6 +2981,10 @@
self.unchanged(a)
a = """sorted(filter(f, 'abc'), key=blah)[0]"""
self.unchanged(a)
+ a = """enumerate(filter(f, 'abc'))"""
+ self.unchanged(a)
+ a = """enumerate(filter(f, 'abc'), start=1)"""
+ self.unchanged(a)
a = """for i in filter(f, 'abc'): pass"""
self.unchanged(a)
a = """[x for x in filter(f, 'abc')]"""
@@ -3089,6 +3093,10 @@
self.unchanged(a)
a = """sorted(map(f, 'abc'), key=blah)[0]"""
self.unchanged(a)
+ a = """enumerate(map(f, 'abc'))"""
+ self.unchanged(a)
+ a = """enumerate(map(f, 'abc'), start=1)"""
+ self.unchanged(a)
a = """for i in map(f, 'abc'): pass"""
self.unchanged(a)
a = """[x for x in map(f, 'abc')]"""
@@ -3152,6 +3160,10 @@
self.unchanged(a)
a = """sorted(zip(a, b), key=blah)[0]"""
self.unchanged(a)
+ a = """enumerate(zip(a, b))"""
+ self.unchanged(a)
+ a = """enumerate(zip(a, b), start=1)"""
+ self.unchanged(a)
a = """for i in zip(a, b): pass"""
self.unchanged(a)
a = """[x for x in zip(a, b)]"""
diff --git a/Misc/NEWS b/Misc/NEWS
--- a/Misc/NEWS
+++ b/Misc/NEWS
@@ -143,6 +143,10 @@
- Issue #16333: use (",", ": ") as default separator when indent is specified
to avoid trailing whitespace. Patch by Serhiy Storchaka.
+- Issue #16573: In 2to3, treat enumerate() like a consuming call, so superfluous
+ list() calls aren't added to filter(), map(), and zip() which are directly
+ passed enumerate().
+
- Issue #16549: Make json.tool work again on Python 3 and add tests.
Initial patch by Berker Peksag and Serhiy Storchaka.
--
Repository URL: http://hg.python.org/cpython
More information about the Python-checkins
mailing list