Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 4089eec

Browse files
committed
merge 3.3 (#16573)
2 parents 1d1210e + daf2829 commit 4089eec

3 files changed

Lines changed: 22 additions & 6 deletions

File tree

Lib/lib2to3/fixer_util.py

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -165,7 +165,7 @@ def parenthesize(node):
165165

166166

167167
consuming_calls = set(["sorted", "list", "set", "any", "all", "tuple", "sum",
168-
"min", "max"])
168+
"min", "max", "enumerate"])
169169

170170
def attr_chain(obj, attr):
171171
"""Follow an attribute chain.
@@ -192,29 +192,29 @@ def attr_chain(obj, attr):
192192
p1 = """
193193
power<
194194
( 'iter' | 'list' | 'tuple' | 'sorted' | 'set' | 'sum' |
195-
'any' | 'all' | (any* trailer< '.' 'join' >) )
195+
'any' | 'all' | 'enumerate' | (any* trailer< '.' 'join' >) )
196196
trailer< '(' node=any ')' >
197197
any*
198198
>
199199
"""
200200
p2 = """
201201
power<
202-
'sorted'
202+
( 'sorted' | 'enumerate' )
203203
trailer< '(' arglist<node=any any*> ')' >
204204
any*
205205
>
206206
"""
207207
pats_built = False
208208
def in_special_context(node):
209209
""" Returns true if node is in an environment where all that is required
210-
of it is being itterable (ie, it doesn't matter if it returns a list
211-
or an itterator).
210+
of it is being iterable (ie, it doesn't matter if it returns a list
211+
or an iterator).
212212
See test_map_nochange in test_fixers.py for some examples and tests.
213213
"""
214214
global p0, p1, p2, pats_built
215215
if not pats_built:
216-
p1 = patcomp.compile_pattern(p1)
217216
p0 = patcomp.compile_pattern(p0)
217+
p1 = patcomp.compile_pattern(p1)
218218
p2 = patcomp.compile_pattern(p2)
219219
pats_built = True
220220
patterns = [p0, p1, p2]

Lib/lib2to3/tests/test_fixers.py

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2981,6 +2981,10 @@ def test_filter_nochange(self):
29812981
self.unchanged(a)
29822982
a = """sorted(filter(f, 'abc'), key=blah)[0]"""
29832983
self.unchanged(a)
2984+
a = """enumerate(filter(f, 'abc'))"""
2985+
self.unchanged(a)
2986+
a = """enumerate(filter(f, 'abc'), start=1)"""
2987+
self.unchanged(a)
29842988
a = """for i in filter(f, 'abc'): pass"""
29852989
self.unchanged(a)
29862990
a = """[x for x in filter(f, 'abc')]"""
@@ -3089,6 +3093,10 @@ def test_map_nochange(self):
30893093
self.unchanged(a)
30903094
a = """sorted(map(f, 'abc'), key=blah)[0]"""
30913095
self.unchanged(a)
3096+
a = """enumerate(map(f, 'abc'))"""
3097+
self.unchanged(a)
3098+
a = """enumerate(map(f, 'abc'), start=1)"""
3099+
self.unchanged(a)
30923100
a = """for i in map(f, 'abc'): pass"""
30933101
self.unchanged(a)
30943102
a = """[x for x in map(f, 'abc')]"""
@@ -3152,6 +3160,10 @@ def test_zip_nochange(self):
31523160
self.unchanged(a)
31533161
a = """sorted(zip(a, b), key=blah)[0]"""
31543162
self.unchanged(a)
3163+
a = """enumerate(zip(a, b))"""
3164+
self.unchanged(a)
3165+
a = """enumerate(zip(a, b), start=1)"""
3166+
self.unchanged(a)
31553167
a = """for i in zip(a, b): pass"""
31563168
self.unchanged(a)
31573169
a = """[x for x in zip(a, b)]"""

Misc/NEWS

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -143,6 +143,10 @@ Library
143143
- Issue #16333: use (",", ": ") as default separator when indent is specified
144144
to avoid trailing whitespace. Patch by Serhiy Storchaka.
145145

146+
- Issue #16573: In 2to3, treat enumerate() like a consuming call, so superfluous
147+
list() calls aren't added to filter(), map(), and zip() which are directly
148+
passed enumerate().
149+
146150
- Issue #16549: Make json.tool work again on Python 3 and add tests.
147151
Initial patch by Berker Peksag and Serhiy Storchaka.
148152

0 commit comments

Comments
 (0)