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

Skip to content

Commit 5c7a251

Browse files
committed
Add tests for recent changes:
- global stmt in class does not affect free vars in methods - locals() works with free and cell vars
1 parent 220ae7c commit 5c7a251

2 files changed

Lines changed: 32 additions & 0 deletions

File tree

Lib/test/output/test_scope

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,3 +15,5 @@ test_scope
1515
14. complex definitions
1616
15. scope of global statements
1717
16. check leaks
18+
17. class and global
19+
18. verify that locals() works

Lib/test/test_scope.py

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -405,3 +405,33 @@ def f2():
405405
f1()
406406

407407
verify(Foo.count == 0)
408+
409+
print "17. class and global"
410+
411+
def test(x):
412+
class Foo:
413+
global x
414+
def __call__(self, y):
415+
return x + y
416+
return Foo()
417+
418+
x = 0
419+
verify(test(6)(2) == 8)
420+
x = -1
421+
verify(test(3)(2) == 5)
422+
423+
print "18. verify that locals() works"
424+
425+
def f(x):
426+
def g(y):
427+
def h(z):
428+
return y + z
429+
w = x + y
430+
y += 3
431+
return locals()
432+
return g
433+
434+
d = f(2)(4)
435+
verify(d.has_key('h'))
436+
del d['h']
437+
verify(d == {'x': 2, 'y': 7, 'w': 6})

0 commit comments

Comments
 (0)