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

Skip to content

Commit 5b44a67

Browse files
committed
Add test to verify that nested functions with free variables don't
cause the free variables to leak.
1 parent 30c9f39 commit 5b44a67

2 files changed

Lines changed: 24 additions & 0 deletions

File tree

Lib/test/output/test_scope

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,3 +14,4 @@ test_scope
1414
13. UnboundLocal
1515
14. complex definitions
1616
15. scope of global statements
17+
16. check leaks

Lib/test/test_scope.py

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -383,3 +383,26 @@ def h():
383383
return g()
384384
verify(f() == 2)
385385
verify(x == 2)
386+
387+
print "16. check leaks"
388+
389+
class Foo:
390+
count = 0
391+
392+
def __init__(self):
393+
Foo.count += 1
394+
395+
def __del__(self):
396+
Foo.count -= 1
397+
398+
def f1():
399+
x = Foo()
400+
def f2():
401+
return x
402+
f2()
403+
404+
for i in range(100):
405+
f1()
406+
407+
verify(Foo.count == 0)
408+

0 commit comments

Comments
 (0)