Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit b3b09c9

Browse files
committed
added builtin b/w compat module.
changed testing of exec.
1 parent b37954f commit b3b09c9

4 files changed

Lines changed: 25 additions & 11 deletions

File tree

Lib/builtin.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
# B/W compat hack so code that says "import builtin" won't break after
2+
# name change from builtin to __builtin__.
3+
from __builtin__ import *

Lib/test/test_b1.py

Lines changed: 1 addition & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ def f2(a1, a2):
2525
raise TestFailed, 'f2 called with ' + `a1, a2`
2626
def f3(a1, a2, a3):
2727
if a1 != 1 or a2 != 2 or a3 != 3:
28-
raise TestFailed, 'f2 called with ' + `a1, a2, a3`
28+
raise TestFailed, 'f3 called with ' + `a1, a2, a3`
2929
apply(f0, ())
3030
apply(f1, (1,))
3131
apply(f2, (1, 2))
@@ -81,14 +81,6 @@ def f3(a1, a2, a3):
8181
if eval('1+1') <> 2: raise TestFailed, 'eval(\'1+1\')'
8282
if eval(' 1+1\n') <> 2: raise TestFailed, 'eval(\' 1+1\\n\')'
8383

84-
print 'exec'
85-
z = 0
86-
exec('z=1+1\n')
87-
if z <> 2: raise TestFailed, 'exec(\'z=1+1\'\\n)'
88-
z = 0
89-
exec('z=1+1')
90-
if z <> 2: raise TestFailed, 'exec(\'z=1+1\')'
91-
9284
print 'execfile'
9385
z = 0
9486
f = open(TESTFN, 'w')

Lib/test/test_grammar.py

Lines changed: 20 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -97,7 +97,7 @@ def v3(a, (b, c), *rest): pass
9797
print 'simple_stmt'
9898
x = 1; pass; del x
9999

100-
### small_stmt: expr_stmt | print_stmt | pass_stmt | del_stmt | flow_stmt | import_stmt
100+
### small_stmt: expr_stmt | print_stmt | pass_stmt | del_stmt | flow_stmt | import_stmt | global_stmt | access_stmt | exec_stmt
101101
# Tested below
102102

103103
print 'expr_stmt' # (exprlist '=')* exprlist
@@ -165,6 +165,25 @@ def f():
165165
global a, b
166166
global one, two, three, four, five, six, seven, eight, nine, ten
167167

168+
print 'exec_stmt' # 'exec' expr ['in' expr [',' expr]]
169+
def f():
170+
z = None
171+
del z
172+
exec 'z=1+1\n'
173+
if z <> 2: raise TestFailed, 'exec \'z=1+1\'\\n'
174+
del z
175+
exec 'z=1+1'
176+
if z <> 2: raise TestFailed, 'exec \'z=1+1\''
177+
f()
178+
g = {}
179+
exec 'z = 1' in g
180+
if g <> {'z': 1}: raise TestFailed, 'exec \'z = 1\' in g'
181+
g = {}
182+
l = {}
183+
exec 'global a; a = 1; b = 2' in g, l
184+
if (g, l) <> ({'a':1}, {'b':2}): raise TestFailed, 'exec ... in g, l'
185+
186+
168187
### compound_stmt: if_stmt | while_stmt | for_stmt | try_stmt | funcdef | classdef
169188
# Tested below
170189

Lib/test/testall.out

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@ import_stmt
3535
[5]
3636
[6]
3737
global_stmt
38+
exec_stmt
3839
if_stmt
3940
while_stmt
4041
for_stmt
@@ -71,7 +72,6 @@ coerce
7172
dir
7273
divmod
7374
eval
74-
exec
7575
execfile
7676
float
7777
getattr

0 commit comments

Comments
 (0)