@@ -2954,10 +2954,23 @@ def test_filter_basic(self):
29542954 a = """x = [x for x in range(10) if x%2 == 0]"""
29552955 self .check (b , a )
29562956
2957- # XXX This (rare) case is not supported
2958- ## b = """x = filter(f, 'abc')[0]"""
2959- ## a = """x = list(filter(f, 'abc'))[0]"""
2960- ## self.check(b, a)
2957+ def test_filter_trailers (self ):
2958+ b = """x = filter(None, 'abc')[0]"""
2959+ a = """x = [_f for _f in 'abc' if _f][0]"""
2960+ self .check (b , a )
2961+
2962+ b = """x = len(filter(f, 'abc')[0])"""
2963+ a = """x = len(list(filter(f, 'abc'))[0])"""
2964+ self .check (b , a )
2965+
2966+ b = """x = filter(lambda x: x%2 == 0, range(10))[0]"""
2967+ a = """x = [x for x in range(10) if x%2 == 0][0]"""
2968+ self .check (b , a )
2969+
2970+ # Note the parens around x
2971+ b = """x = filter(lambda (x): x%2 == 0, range(10))[0]"""
2972+ a = """x = [x for x in range(10) if x%2 == 0][0]"""
2973+ self .check (b , a )
29612974
29622975 def test_filter_nochange (self ):
29632976 a = """b.join(filter(f, 'abc'))"""
@@ -3022,6 +3035,23 @@ def test_prefix_preservation(self):
30223035 a = """x = list(map( f, 'abc' ))"""
30233036 self .check (b , a )
30243037
3038+ def test_map_trailers (self ):
3039+ b = """x = map(f, 'abc')[0]"""
3040+ a = """x = list(map(f, 'abc'))[0]"""
3041+ self .check (b , a )
3042+
3043+ b = """x = map(None, l)[0]"""
3044+ a = """x = list(l)[0]"""
3045+ self .check (b , a )
3046+
3047+ b = """x = map(lambda x:x, l)[0]"""
3048+ a = """x = [x for x in l][0]"""
3049+ self .check (b , a )
3050+
3051+ b = """x = map(f, 'abc')[0][1]"""
3052+ a = """x = list(map(f, 'abc'))[0][1]"""
3053+ self .check (b , a )
3054+
30253055 def test_trailing_comment (self ):
30263056 b = """x = map(f, 'abc') # foo"""
30273057 a = """x = list(map(f, 'abc')) # foo"""
@@ -3066,11 +3096,6 @@ def test_map_basic(self):
30663096 """
30673097 self .warns (b , a , "You should use a for loop here" )
30683098
3069- # XXX This (rare) case is not supported
3070- ## b = """x = map(f, 'abc')[0]"""
3071- ## a = """x = list(map(f, 'abc'))[0]"""
3072- ## self.check(b, a)
3073-
30743099 def test_map_nochange (self ):
30753100 a = """b.join(map(f, 'abc'))"""
30763101 self .unchanged (a )
@@ -3130,6 +3155,10 @@ def check(self, b, a):
31303155 super (Test_zip , self ).check (b , a )
31313156
31323157 def test_zip_basic (self ):
3158+ b = """x = zip()"""
3159+ a = """x = list(zip())"""
3160+ self .check (b , a )
3161+
31333162 b = """x = zip(a, b, c)"""
31343163 a = """x = list(zip(a, b, c))"""
31353164 self .check (b , a )
@@ -3138,6 +3167,15 @@ def test_zip_basic(self):
31383167 a = """x = len(list(zip(a, b)))"""
31393168 self .check (b , a )
31403169
3170+ def test_zip_trailers (self ):
3171+ b = """x = zip(a, b, c)[0]"""
3172+ a = """x = list(zip(a, b, c))[0]"""
3173+ self .check (b , a )
3174+
3175+ b = """x = zip(a, b, c)[0][1]"""
3176+ a = """x = list(zip(a, b, c))[0][1]"""
3177+ self .check (b , a )
3178+
31413179 def test_zip_nochange (self ):
31423180 a = """b.join(zip(a, b))"""
31433181 self .unchanged (a )
0 commit comments