summaryrefslogtreecommitdiffstats
path: root/Lib/lib2to3
diff options
context:
space:
mode:
authorBenjamin Peterson <benjamin@python.org>2012-11-29 15:55:22 (GMT)
committerBenjamin Peterson <benjamin@python.org>2012-11-29 15:55:22 (GMT)
commit57af38700a42f7c037eab85f107800d50d641198 (patch)
tree3c97439a865e1a35375b2b3ed025a38ca424907b /Lib/lib2to3
parent718df1d6384da5285e5c2e5cab6584bf10350513 (diff)
downloadcpython-57af38700a42f7c037eab85f107800d50d641198.zip
cpython-57af38700a42f7c037eab85f107800d50d641198.tar.gz
cpython-57af38700a42f7c037eab85f107800d50d641198.tar.bz2
enumerate only requires an iterable (closes #16573)
Patch by Jonathan Kotta.
Diffstat (limited to 'Lib/lib2to3')
-rw-r--r--Lib/lib2to3/fixer_util.py12
-rw-r--r--Lib/lib2to3/tests/test_fixers.py12
2 files changed, 18 insertions, 6 deletions
diff --git a/Lib/lib2to3/fixer_util.py b/Lib/lib2to3/fixer_util.py
index 2b5bb1d..60d219f 100644
--- a/Lib/lib2to3/fixer_util.py
+++ b/Lib/lib2to3/fixer_util.py
@@ -165,7 +165,7 @@ def parenthesize(node):
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 @@ p0 = """for_stmt< 'for' any 'in' node=any ':' any* >
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 @@ power<
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:
- p1 = patcomp.compile_pattern(p1)
p0 = patcomp.compile_pattern(p0)
+ p1 = patcomp.compile_pattern(p1)
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
index 43184e1..914b3bf 100644
--- a/Lib/lib2to3/tests/test_fixers.py
+++ b/Lib/lib2to3/tests/test_fixers.py
@@ -2981,6 +2981,10 @@ class Test_filter(FixerTestCase):
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 @@ class Test_map(FixerTestCase):
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 @@ class Test_zip(FixerTestCase):
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)]"""