1# test builtin exec 2 3try: 4 exec 5except NameError: 6 print("SKIP") 7 raise SystemExit 8 9print(exec("def foo(): return 42")) 10print(foo()) 11 12d = {} 13exec("def bar(): return 84", d) 14print(d["bar"]()) 15 16# passing None/dict as args to globals/locals 17foo = 11 18exec('print(foo)') 19exec('print(foo)', None) 20exec('print(foo)', {'foo':3}, None) 21exec('print(foo)', None, {'foo':3}) 22exec('print(foo)', None, {'bar':3}) 23exec('print(foo)', {'bar':3}, locals()) 24 25try: 26 exec('print(foo)', {'bar':3}, None) 27except NameError: 28 print('NameError') 29 30# invalid arg passed to globals 31try: 32 exec('print(1)', 'foo') 33except TypeError: 34 print('TypeError') 35 36# invalid arg passed to locals 37try: 38 exec('print(1)', None, 123) 39except TypeError: 40 print('TypeError') 41