From: Fred Drake Date: Mon, 10 Dec 2001 23:46:02 +0000 (+0000) Subject: Regression test for SF bug #478534 -- exceptions could "leak" into a weakref X-Git-Tag: v2.2.1c1~434 X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=2a64f4693ddcd552c4c6e709eaaba7cf829464d8;p=python Regression test for SF bug #478534 -- exceptions could "leak" into a weakref callback. --- diff --git a/Lib/test/test_weakref.py b/Lib/test/test_weakref.py index 1623039130..7f4870e187 100644 --- a/Lib/test/test_weakref.py +++ b/Lib/test/test_weakref.py @@ -227,6 +227,31 @@ class ReferencesTestCase(TestBase): self.assert_(p + 1.0 == 3.0) self.assert_(1.0 + p == 3.0) # this used to SEGV + def test_callbacks_protected(self): + """Callbacks protected from already-set exceptions?""" + # Regression test for SF bug #478534. + class BogusError(Exception): + pass + data = {} + def remove(k): + del data[k] + def encapsulate(): + f = lambda : () + data[weakref.ref(f, remove)] = None + raise BogusError + try: + encapsulate() + except BogusError: + pass + else: + self.fail("exception not properly restored") + try: + encapsulate() + except BogusError: + pass + else: + self.fail("exception not properly restored") + class Object: def __init__(self, arg):