@@ -2954,10 +2954,23 @@ def test_filter_basic(self):
2954
2954
a = """x = [x for x in range(10) if x%2 == 0]"""
2955
2955
self .check (b , a )
2956
2956
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 )
2961
2974
2962
2975
def test_filter_nochange (self ):
2963
2976
a = """b.join(filter(f, 'abc'))"""
@@ -3022,6 +3035,23 @@ def test_prefix_preservation(self):
3022
3035
a = """x = list(map( f, 'abc' ))"""
3023
3036
self .check (b , a )
3024
3037
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
+
3025
3055
def test_trailing_comment (self ):
3026
3056
b = """x = map(f, 'abc') # foo"""
3027
3057
a = """x = list(map(f, 'abc')) # foo"""
@@ -3066,11 +3096,6 @@ def test_map_basic(self):
3066
3096
"""
3067
3097
self .warns (b , a , "You should use a for loop here" )
3068
3098
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
-
3074
3099
def test_map_nochange (self ):
3075
3100
a = """b.join(map(f, 'abc'))"""
3076
3101
self .unchanged (a )
@@ -3130,6 +3155,10 @@ def check(self, b, a):
3130
3155
super (Test_zip , self ).check (b , a )
3131
3156
3132
3157
def test_zip_basic (self ):
3158
+ b = """x = zip()"""
3159
+ a = """x = list(zip())"""
3160
+ self .check (b , a )
3161
+
3133
3162
b = """x = zip(a, b, c)"""
3134
3163
a = """x = list(zip(a, b, c))"""
3135
3164
self .check (b , a )
@@ -3138,6 +3167,15 @@ def test_zip_basic(self):
3138
3167
a = """x = len(list(zip(a, b)))"""
3139
3168
self .check (b , a )
3140
3169
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
+
3141
3179
def test_zip_nochange (self ):
3142
3180
a = """b.join(zip(a, b))"""
3143
3181
self .unchanged (a )
0 commit comments