Add test to verify that nested functions with free variables don't
authorJeremy Hylton <jeremy@alum.mit.edu>
Tue, 13 Mar 2001 02:01:12 +0000 (02:01 +0000)
committerJeremy Hylton <jeremy@alum.mit.edu>
Tue, 13 Mar 2001 02:01:12 +0000 (02:01 +0000)
cause the free variables to leak.

Lib/test/output/test_scope
Lib/test/test_scope.py

index 5d41e8c384e1240722f30365315af7a6387b76c6..b00f9f51677341df3fa55014161ca6662867ec6a 100644 (file)
@@ -14,3 +14,4 @@ test_scope
 13. UnboundLocal
 14. complex definitions
 15. scope of global statements
+16. check leaks
index 0633b1433f944889d04a5c5de9f66b9a38fdfdc5..4bd8ed7ea9b39459379f57dc36b7f5ae5295134f 100644 (file)
@@ -383,3 +383,26 @@ def f():
     return g()
 verify(f() == 2)
 verify(x == 2)
+
+print "16. check leaks"
+
+class Foo:
+    count = 0
+    
+    def __init__(self):
+        Foo.count += 1
+
+    def __del__(self):
+        Foo.count -= 1
+
+def f1():
+    x = Foo()
+    def f2():
+        return x
+    f2()
+    
+for i in range(100):
+    f1()
+
+verify(Foo.count == 0)
+