mirror of
https://github.com/python/cpython.git
synced 2025-08-27 12:16:04 +00:00
SF patch 1631942 by Collin Winter:
(a) "except E, V" -> "except E as V" (b) V is now limited to a simple name (local variable) (c) V is now deleted at the end of the except block
This commit is contained in:
parent
893523e80a
commit
b940e113bf
295 changed files with 817 additions and 743 deletions
|
@ -21,17 +21,17 @@ class ExceptionTests(unittest.TestCase):
|
|||
try:
|
||||
import exceptions
|
||||
reload(exceptions)
|
||||
except ImportError, e:
|
||||
except ImportError as e:
|
||||
self.fail("reloading exceptions: %s" % e)
|
||||
|
||||
def raise_catch(self, exc, excname):
|
||||
try:
|
||||
raise exc, "spam"
|
||||
except exc, err:
|
||||
except exc as err:
|
||||
buf1 = str(err)
|
||||
try:
|
||||
raise exc("spam")
|
||||
except exc, err:
|
||||
except exc as err:
|
||||
buf2 = str(err)
|
||||
self.assertEquals(buf1, buf2)
|
||||
self.assertEquals(exc.__name__, excname)
|
||||
|
@ -115,7 +115,7 @@ class ExceptionTests(unittest.TestCase):
|
|||
|
||||
self.raise_catch(Exception, "Exception")
|
||||
try: x = 1/0
|
||||
except Exception, e: pass
|
||||
except Exception as e: pass
|
||||
|
||||
def testSyntaxErrorMessage(self):
|
||||
# make sure the right exception message is raised for each of
|
||||
|
@ -124,7 +124,7 @@ class ExceptionTests(unittest.TestCase):
|
|||
def ckmsg(src, msg):
|
||||
try:
|
||||
compile(src, '<fragment>', 'exec')
|
||||
except SyntaxError, e:
|
||||
except SyntaxError as e:
|
||||
if e.msg != msg:
|
||||
self.fail("expected %s, got %s" % (msg, e.msg))
|
||||
else:
|
||||
|
@ -163,7 +163,7 @@ class ExceptionTests(unittest.TestCase):
|
|||
import _testcapi
|
||||
try:
|
||||
_testcapi.raise_exception(BadException, 1)
|
||||
except TypeError, err:
|
||||
except TypeError as err:
|
||||
exc, err, tb = sys.exc_info()
|
||||
co = tb.tb_frame.f_code
|
||||
self.assertEquals(co.co_name, "test_capi1")
|
||||
|
@ -175,7 +175,7 @@ class ExceptionTests(unittest.TestCase):
|
|||
import _testcapi
|
||||
try:
|
||||
_testcapi.raise_exception(BadException, 0)
|
||||
except RuntimeError, err:
|
||||
except RuntimeError as err:
|
||||
exc, err, tb = sys.exc_info()
|
||||
co = tb.tb_frame.f_code
|
||||
self.assertEquals(co.co_name, "__init__")
|
||||
|
@ -285,7 +285,7 @@ class ExceptionTests(unittest.TestCase):
|
|||
for exc, args, expected in exceptionList:
|
||||
try:
|
||||
raise exc(*args)
|
||||
except BaseException, e:
|
||||
except BaseException as e:
|
||||
if type(e) is not exc:
|
||||
raise
|
||||
# Verify module name
|
||||
|
@ -344,6 +344,16 @@ class ExceptionTests(unittest.TestCase):
|
|||
self.failUnless(str(Exception('a')))
|
||||
self.failUnless(unicode(Exception(u'a')))
|
||||
|
||||
def testExceptionCleanup(self):
|
||||
# Make sure "except V as N" exceptions are cleaned up properly
|
||||
|
||||
try:
|
||||
raise Exception()
|
||||
except Exception as e:
|
||||
self.failUnless(e)
|
||||
del e
|
||||
self.failIf('e' in locals())
|
||||
|
||||
|
||||
def test_main():
|
||||
run_unittest(ExceptionTests)
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue