Skip to content

Commit 6cfe737

Browse files
tomlogicdpgeorge
authored andcommitted
tests/basics/builtin_exec: Test various globals/locals args to exec().
1 parent bb3bdda commit 6cfe737

File tree

1 file changed

+26
-0
lines changed

1 file changed

+26
-0
lines changed

tests/basics/builtin_exec.py

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,3 +4,29 @@
44
d = {}
55
exec("def bar(): return 84", d)
66
print(d["bar"]())
7+
8+
# passing None/dict as args to globals/locals
9+
foo = 11
10+
exec('print(foo)')
11+
exec('print(foo)', None)
12+
exec('print(foo)', {'foo':3}, None)
13+
exec('print(foo)', None, {'foo':3})
14+
exec('print(foo)', None, {'bar':3})
15+
exec('print(foo)', {'bar':3}, locals())
16+
17+
try:
18+
exec('print(foo)', {'bar':3}, None)
19+
except NameError:
20+
print('NameError')
21+
22+
# invalid arg passed to globals
23+
try:
24+
exec('print(1)', 'foo')
25+
except TypeError:
26+
print('TypeError')
27+
28+
# invalid arg passed to locals
29+
try:
30+
exec('print(1)', None, 123)
31+
except TypeError:
32+
print('TypeError')

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy