From: Jeremy Hylton Date: Tue, 13 Mar 2001 02:01:12 +0000 (+0000) Subject: Add test to verify that nested functions with free variables don't X-Git-Tag: v2.1b2~179 X-Git-Url: http://git.ipfire.org/gitweb.cgi?a=commitdiff_plain;h=5b44a67bdb67545679a2e1bfcf482996f8d8abb5;p=thirdparty%2FPython%2Fcpython.git Add test to verify that nested functions with free variables don't cause the free variables to leak. --- diff --git a/Lib/test/output/test_scope b/Lib/test/output/test_scope index 5d41e8c384e1..b00f9f516773 100644 --- a/Lib/test/output/test_scope +++ b/Lib/test/output/test_scope @@ -14,3 +14,4 @@ test_scope 13. UnboundLocal 14. complex definitions 15. scope of global statements +16. check leaks diff --git a/Lib/test/test_scope.py b/Lib/test/test_scope.py index 0633b1433f94..4bd8ed7ea9b3 100644 --- a/Lib/test/test_scope.py +++ b/Lib/test/test_scope.py @@ -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) +