From: Miss Islington (bot) <31488909+miss-islington@users.noreply.github.com> Date: Tue, 15 Oct 2024 14:28:23 +0000 (+0200) Subject: [3.12] gh-125514: fix bug in test_traceback utility. Specify exception types in excep... X-Git-Tag: v3.12.8~203 X-Git-Url: http://git.ipfire.org/gitweb.cgi?a=commitdiff_plain;h=26725d1756424b8abff896ffed7b017dd59241fc;p=thirdparty%2FPython%2Fcpython.git [3.12] gh-125514: fix bug in test_traceback utility. Specify exception types in except: clauses (GH-125516) (#125525) gh-125514: fix bug in test_traceback utility. Specify exception types in except: clauses (GH-125516) (cherry picked from commit 55c4f4c30b49734ce35dc88139b8b4fdc94c66fd) Co-authored-by: Irit Katriel <1055913+iritkatriel@users.noreply.github.com> --- diff --git a/Lib/test/test_traceback.py b/Lib/test/test_traceback.py index d12b559cf076..119143e4f3a0 100644 --- a/Lib/test/test_traceback.py +++ b/Lib/test/test_traceback.py @@ -138,7 +138,7 @@ class TracebackCases(unittest.TestCase): import traceback try: x = 1 / 0 - except: + except ZeroDivisionError: traceback.print_exc() """) try: @@ -386,9 +386,10 @@ class PurePythonExceptionFormattingMixin: def get_exception(self, callable, slice_start=0, slice_end=-1): try: callable() - self.fail("No exception thrown.") - except: + except BaseException: return traceback.format_exc().splitlines()[slice_start:slice_end] + else: + self.fail("No exception thrown.") callable_line = get_exception.__code__.co_firstlineno + 2 @@ -1490,7 +1491,7 @@ class BaseExceptionReportingTests: try: try: raise Exception - except: + except Exception: raise ZeroDivisionError from None except ZeroDivisionError as _: e = _ @@ -1838,9 +1839,9 @@ class BaseExceptionReportingTests: try: try: raise EG("eg1", [ValueError(1), TypeError(2)]) - except: + except EG: raise EG("eg2", [ValueError(3), TypeError(4)]) - except: + except EG: raise ImportError(5) expected = ( @@ -1889,7 +1890,7 @@ class BaseExceptionReportingTests: except Exception as e: exc = e raise EG("eg", [VE(1), exc, VE(4)]) - except: + except EG: raise EG("top", [VE(5)]) expected = (f' + Exception Group Traceback (most recent call last):\n' @@ -2642,7 +2643,7 @@ class TestTracebackException(unittest.TestCase): def f(): try: 1/0 - except: + except ZeroDivisionError: f() try: @@ -2731,7 +2732,7 @@ class TestTracebackException(unittest.TestCase): def raise_exc(): try: raise ValueError('bad value') - except: + except ValueError: raise def raise_with_locals():