◐ Shell
clean mode source ↗

[3.6] bpo-28837: Fix lib2to3 handling of map/zip/filter calls when fo… by Mariatta · Pull Request #2235 · python/cpython

Expand Up @@ -2954,10 +2954,23 @@ def test_filter_basic(self): a = """x = [x for x in range(10) if x%2 == 0]""" self.check(b, a)
# XXX This (rare) case is not supported ## b = """x = filter(f, 'abc')[0]""" ## a = """x = list(filter(f, 'abc'))[0]""" ## self.check(b, a) def test_filter_trailers(self): b = """x = filter(None, 'abc')[0]""" a = """x = [_f for _f in 'abc' if _f][0]""" self.check(b, a)
b = """x = len(filter(f, 'abc')[0])""" a = """x = len(list(filter(f, 'abc'))[0])""" self.check(b, a)
b = """x = filter(lambda x: x%2 == 0, range(10))[0]""" a = """x = [x for x in range(10) if x%2 == 0][0]""" self.check(b, a)
# Note the parens around x b = """x = filter(lambda (x): x%2 == 0, range(10))[0]""" a = """x = [x for x in range(10) if x%2 == 0][0]""" self.check(b, a)
def test_filter_nochange(self): a = """b.join(filter(f, 'abc'))""" Expand Down Expand Up @@ -3022,6 +3035,23 @@ def test_prefix_preservation(self): a = """x = list(map( f, 'abc' ))""" self.check(b, a)
def test_map_trailers(self): b = """x = map(f, 'abc')[0]""" a = """x = list(map(f, 'abc'))[0]""" self.check(b, a)
b = """x = map(None, l)[0]""" a = """x = list(l)[0]""" self.check(b, a)
b = """x = map(lambda x:x, l)[0]""" a = """x = [x for x in l][0]""" self.check(b, a)
b = """x = map(f, 'abc')[0][1]""" a = """x = list(map(f, 'abc'))[0][1]""" self.check(b, a)
def test_trailing_comment(self): b = """x = map(f, 'abc') # foo""" a = """x = list(map(f, 'abc')) # foo""" Expand Down Expand Up @@ -3066,11 +3096,6 @@ def test_map_basic(self): """ self.warns(b, a, "You should use a for loop here")
# XXX This (rare) case is not supported ## b = """x = map(f, 'abc')[0]""" ## a = """x = list(map(f, 'abc'))[0]""" ## self.check(b, a)
def test_map_nochange(self): a = """b.join(map(f, 'abc'))""" self.unchanged(a) Expand Down Expand Up @@ -3130,6 +3155,10 @@ def check(self, b, a): super(Test_zip, self).check(b, a)
def test_zip_basic(self): b = """x = zip()""" a = """x = list(zip())""" self.check(b, a)
b = """x = zip(a, b, c)""" a = """x = list(zip(a, b, c))""" self.check(b, a) Expand All @@ -3138,6 +3167,15 @@ def test_zip_basic(self): a = """x = len(list(zip(a, b)))""" self.check(b, a)
def test_zip_trailers(self): b = """x = zip(a, b, c)[0]""" a = """x = list(zip(a, b, c))[0]""" self.check(b, a)
b = """x = zip(a, b, c)[0][1]""" a = """x = list(zip(a, b, c))[0][1]""" self.check(b, a)
def test_zip_nochange(self): a = """b.join(zip(a, b))""" self.unchanged(a) Expand Down