@@ -246,7 +246,7 @@ def test_any(self):
246246 S = [10 , 20 , 30 ]
247247 self .assertEqual (any (x > 42 for x in S ), False )
248248
249- def test_all_any_tuple_optimization (self ):
249+ def test_all_any_tuple_list_optimization (self ):
250250 def f_all ():
251251 return all (x - 2 for x in [1 ,2 ,3 ])
252252
@@ -256,7 +256,10 @@ def f_any():
256256 def f_tuple ():
257257 return tuple (2 * x for x in [1 ,2 ,3 ])
258258
259- funcs = [f_all , f_any , f_tuple ]
259+ def f_list ():
260+ return list (2 * x for x in [1 ,2 ,3 ])
261+
262+ funcs = [f_all , f_any , f_tuple , f_list ]
260263
261264 for f in funcs :
262265 # check that generator code object is not duplicated
@@ -266,33 +269,33 @@ def f_tuple():
266269
267270 # check the overriding the builtins works
268271
269- global all , any , tuple
270- saved = all , any , tuple
272+ global all , any , tuple , list
273+ saved = all , any , tuple , list
271274 try :
272275 all = lambda x : "all"
273276 any = lambda x : "any"
274277 tuple = lambda x : "tuple"
278+ list = lambda x : "list"
275279
276280 overridden_outputs = [f () for f in funcs ]
277281 finally :
278- all , any , tuple = saved
279-
280- self .assertEqual (overridden_outputs , ['all' , 'any' , 'tuple' ])
282+ all , any , tuple , list = saved
281283
284+ self .assertEqual (overridden_outputs , ['all' , 'any' , 'tuple' , 'list' ])
282285 # Now repeat, overriding the builtins module as well
283- saved = all , any , tuple
286+ saved = all , any , tuple , list
284287 try :
285288 builtins .all = all = lambda x : "all"
286289 builtins .any = any = lambda x : "any"
287290 builtins .tuple = tuple = lambda x : "tuple"
291+ builtins .list = list = lambda x : "list"
288292
289293 overridden_outputs = [f () for f in funcs ]
290294 finally :
291- all , any , tuple = saved
292- builtins .all , builtins .any , builtins .tuple = saved
293-
294- self .assertEqual (overridden_outputs , ['all' , 'any' , 'tuple' ])
295+ all , any , tuple , list = saved
296+ builtins .all , builtins .any , builtins .tuple , builtins .list = saved
295297
298+ self .assertEqual (overridden_outputs , ['all' , 'any' , 'tuple' , 'list' ])
296299
297300 def test_ascii (self ):
298301 self .assertEqual (ascii ('' ), '\' \' ' )
0 commit comments