@@ -74,49 +74,57 @@ def f():
74
74
result .append (i ) # Ok
75
75
76
76
77
- def f ():
77
+ async def f ():
78
78
items = [1 , 2 , 3 , 4 ]
79
79
result = []
80
80
async for i in items :
81
81
if i % 2 :
82
82
result .append (i ) # PERF401
83
83
84
84
85
- def f ():
85
+ async def f ():
86
86
items = [1 , 2 , 3 , 4 ]
87
87
result = []
88
88
async for i in items :
89
89
result .append (i ) # PERF401
90
90
91
91
92
+ async def f ():
93
+ items = [1 , 2 , 3 , 4 ]
94
+ result = [1 , 2 ]
95
+ async for i in items :
96
+ result .append (i ) # PERF401
97
+
98
+
92
99
def f ():
93
- result , _ = [1 ,2 , 3 , 4 ], ...
100
+ result , _ = [1 , 2 , 3 , 4 ], ...
94
101
for i in range (10 ):
95
- result .append (i * 2 ) # PERF401
102
+ result .append (i * 2 ) # PERF401
96
103
97
104
98
105
def f ():
99
106
result = []
100
107
if True :
101
108
for i in range (10 ): # single-line comment 1 should be protected
102
109
# single-line comment 2 should be protected
103
- if i % 2 : # single-line comment 3 should be protected
104
- result .append (i ) # PERF401
110
+ if i % 2 : # single-line comment 3 should be protected
111
+ result .append (i ) # PERF401
105
112
106
113
107
114
def f ():
108
- result = [] # comment after assignment should be protected
115
+ result = [] # comment after assignment should be protected
109
116
for i in range (10 ): # single-line comment 1 should be protected
110
117
# single-line comment 2 should be protected
111
- if i % 2 : # single-line comment 3 should be protected
112
- result .append (i ) # PERF401
118
+ if i % 2 : # single-line comment 3 should be protected
119
+ result .append (i ) # PERF401
113
120
114
121
115
122
def f ():
116
123
result = []
117
124
for i in range (10 ):
118
125
"""block comment stops the fix"""
119
- result .append (i * 2 ) # Ok
126
+ result .append (i * 2 ) # Ok
127
+
120
128
121
129
def f (param ):
122
130
# PERF401
@@ -125,3 +133,107 @@ def f(param):
125
133
new_layers = []
126
134
for value in param :
127
135
new_layers .append (value * 3 )
136
+
137
+
138
+ def f ():
139
+ result = []
140
+ var = 1
141
+ for _ in range (10 ):
142
+ result .append (var + 1 ) # PERF401
143
+
144
+
145
+ def f ():
146
+ # make sure that `tmp` is not deleted
147
+ tmp = 1 ; result = [] # commment should be protected
148
+ for i in range (10 ):
149
+ result .append (i + 1 ) # PERF401
150
+
151
+
152
+ def f ():
153
+ # make sure that `tmp` is not deleted
154
+ result = []; tmp = 1 # commment should be protected
155
+ for i in range (10 ):
156
+ result .append (i + 1 ) # PERF401
157
+
158
+
159
+ def f ():
160
+ result = [] # comment should be protected
161
+ for i in range (10 ):
162
+ result .append (i * 2 ) # PERF401
163
+
164
+
165
+ def f ():
166
+ result = []
167
+ result .append (1 )
168
+ for i in range (10 ):
169
+ result .append (i * 2 ) # PERF401
170
+
171
+
172
+ def f ():
173
+ result = []
174
+ result += [1 ]
175
+ for i in range (10 ):
176
+ result .append (i * 2 ) # PERF401
177
+
178
+
179
+ def f ():
180
+ result = []
181
+ for val in range (5 ):
182
+ result .append (val * 2 ) # Ok
183
+ print (val )
184
+
185
+
186
+ def f ():
187
+ result = []
188
+ for val in range (5 ):
189
+ result .append (val * 2 ) # PERF401
190
+ val = 1
191
+ print (val )
192
+
193
+
194
+ def f ():
195
+ i = [1 , 2 , 3 ]
196
+ result = []
197
+ for i in i :
198
+ result .append (i + 1 ) # PERF401
199
+
200
+
201
+ def f ():
202
+ result = []
203
+ for i in range ( # Comment 1 should not be duplicated
204
+ (
205
+ 2 # Comment 2
206
+ + 1
207
+ )
208
+ ): # Comment 3
209
+ if i % 2 : # Comment 4
210
+ result .append (
211
+ (
212
+ i + 1 ,
213
+ # Comment 5
214
+ 2 ,
215
+ )
216
+ ) # PERF401
217
+
218
+
219
+ def f ():
220
+ result : list [int ] = []
221
+ for i in range (10 ):
222
+ result .append (i * 2 ) # PERF401
223
+
224
+
225
+ def f ():
226
+ a , b = [1 , 2 , 3 ], [4 , 5 , 6 ]
227
+ result = []
228
+ for i in a , b :
229
+ result .append (i [0 ] + i [1 ]) # PERF401
230
+ return result
231
+
232
+
233
+ def f ():
234
+ values = [1 , 2 , 3 ]
235
+ result = []
236
+ for a in values :
237
+ print (a )
238
+ for a in values :
239
+ result .append (a + 1 ) # PERF401
0 commit comments