Rietveld Code Review Tool
Help | Bug tracker | Discussion group | Source code | Sign in
(87)

Unified Diff: Lib/test/test_exceptions.py

Issue 842: Exception state lives too long in 3.0 (Closed) SVN Base: http://svn.python.org/view/*checkout*/python/branches/py3k/
Patch Set: Created 1 year, 7 months ago
Use n/p to move between diff chunks; N/P to move between comments. Please Sign in to add in-line comments.
Jump to:
View side by-side-diff with in-line comments
Download patch
« no previous file | Python/ceval.c » ('j') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: Lib/test/test_exceptions.py
===================================================================
--- Lib/test/test_exceptions.py (revision 62647)
+++ Lib/test/test_exceptions.py (working copy)
@@ -4,6 +4,7 @@
import sys
import unittest
import pickle
+import weakref
from test.test_support import TESTFN, unlink, run_unittest
@@ -400,8 +401,9 @@
self.failUnless(str(Exception('a')))
self.failUnless(str(Exception('a')))
- def testExceptionCleanup(self):
- # Make sure "except V as N" exceptions are cleaned up properly
+ def testExceptionCleanupNames(self):
108414_gmail.com 2008/05/02 23:19:14 This is a test.
+ # Make sure the local variable bound to the exception instance by
+ # an "except" statement is only visible inside the except block.
try:
raise Exception()
@@ -410,7 +412,32 @@
del e
self.failIf('e' in locals())
jhylton 2008/05/06 12:59:48 This test isn't too obvious. The del e seems like
Antoine Pitrou 2008/05/06 15:19:41 On 2008/05/06 12:59:48, jhylton wrote: > This test
+ def testExceptionCleanupState(self):
+ # Make sure exception state is cleaned up as soon as the except
+ # block is left. See #2507
+ class MyException(Exception):
+ def __init__(self, obj):
+ self.obj = obj
+ class MyObj:
+ pass
+
+ def inner_raising_func():
+ # Create some references in exception value and traceback
+ local_ref = obj
+ raise MyException(obj)
jhylton 2008/05/06 12:59:48 Are both references necessary? Will the test fail
Antoine Pitrou 2008/05/06 15:19:41 On 2008/05/06 12:59:48, jhylton wrote: > Are both
+
+ obj = MyObj()
+ wr = weakref.ref(obj)
+ try:
+ inner_raising_func()
+ except MyException as e:
+ pass
+ obj = None
Jeffrey Yasskin 2008/05/03 19:20:06 Comment that this line exists to kill the referenc
+ obj = wr()
+ self.failUnless(obj is None, "%s" % obj)
+
+
def test_main():
run_unittest(ExceptionTests)
« no previous file | Python/ceval.c » ('j')

Powered by Google App Engine
RSS Feeds Recent Issues | This issue
This is Rietveld r497