@@ -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_list_optimization (self ):
249+ def test_all_any_tuple_list_set_optimization (self ):
250250 def f_all ():
251251 return all (x - 2 for x in [1 ,2 ,3 ])
252252
@@ -259,7 +259,10 @@ def f_tuple():
259259 def f_list ():
260260 return list (2 * x for x in [1 ,2 ,3 ])
261261
262- funcs = [f_all , f_any , f_tuple , f_list ]
262+ def f_set ():
263+ return set (2 * x for x in [1 ,2 ,3 ])
264+
265+ funcs = [f_all , f_any , f_tuple , f_list , f_set ]
263266
264267 for f in funcs :
265268 # check that generator code object is not duplicated
@@ -269,33 +272,35 @@ def f_list():
269272
270273 # check the overriding the builtins works
271274
272- global all , any , tuple , list
273- saved = all , any , tuple , list
275+ global all , any , tuple , list , set
276+ saved = all , any , tuple , list , set
274277 try :
275278 all = lambda x : "all"
276279 any = lambda x : "any"
277280 tuple = lambda x : "tuple"
278281 list = lambda x : "list"
282+ set = lambda x : "set"
279283
280284 overridden_outputs = [f () for f in funcs ]
281285 finally :
282- all , any , tuple , list = saved
286+ all , any , tuple , list , set = saved
283287
284- self .assertEqual (overridden_outputs , ['all' , 'any' , 'tuple' , 'list' ])
288+ self .assertEqual (overridden_outputs , ['all' , 'any' , 'tuple' , 'list' , 'set' ])
285289 # Now repeat, overriding the builtins module as well
286- saved = all , any , tuple , list
290+ saved = all , any , tuple , list , set
287291 try :
288292 builtins .all = all = lambda x : "all"
289293 builtins .any = any = lambda x : "any"
290294 builtins .tuple = tuple = lambda x : "tuple"
291295 builtins .list = list = lambda x : "list"
296+ builtins .set = set = lambda x : "set"
292297
293298 overridden_outputs = [f () for f in funcs ]
294299 finally :
295- all , any , tuple , list = saved
296- builtins .all , builtins .any , builtins .tuple , builtins .list = saved
300+ all , any , tuple , list , set = saved
301+ builtins .all , builtins .any , builtins .tuple , builtins .list , builtins . set = saved
297302
298- self .assertEqual (overridden_outputs , ['all' , 'any' , 'tuple' , 'list' ])
303+ self .assertEqual (overridden_outputs , ['all' , 'any' , 'tuple' , 'list' , 'set' ])
299304
300305 def test_ascii (self ):
301306 self .assertEqual (ascii ('' ), '\' \' ' )
0 commit comments