8000 [3.13] gh-125514: fix bug in test_traceback utility. Specify exceptio… · python/cpython@3b8477b · GitHub
[go: up one dir, main page]

Skip to content

Commit 3b8477b

Browse files
[3.13] gh-125514: fix bug in test_traceback utility. Specify exception types in except: clauses (GH-125516) (#125524)
gh-125514: fix bug in test_traceback utility. Specify exception types in except: clauses (GH-125516) (cherry picked from commit 55c4f4c) Co-authored-by: Irit Katriel <1055913+iritkatriel@users.noreply.github.com>
1 parent 35d9624 commit 3b8477b

File tree

1 file changed

+10
-9
lines changed

1 file changed

+10
-9
lines changed

Lib/test/test_traceback.py

Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -150,7 +150,7 @@ def test_no_caret_with_no_debug_ranges_flag_python_traceback(self):
150150
import traceback
151151
try:
152152
x = 1 / 0
153-
except:
153+
except ZeroDivisionError:
154154
traceback.print_exc()
155155
""")
156156
try:
@@ -550,9 +550,10 @@ class PurePythonExceptionFormattingMixin:
550550
def get_exception(self, callable, slice_start=0, slice_end=-1):
551551
try:
552552
callable()
553-
self.fail("No exception thrown.")
554-
except:
553+
except BaseException:
555554
return traceback.format_exc().splitlines()[slice_start:slice_end]
555+
else:
556+
self.fail("No exception thrown.")
556557

557558
callable_line = get_exception.__code__.co_firstlineno + 2
558559

@@ -2234,7 +2235,7 @@ def test_context_suppression(self):
22342235
try:
22352236
try:
22362237
raise Exception
2237-
except:
2238+
except Exception:
22382239
raise ZeroDivisionError from None
22392240
except ZeroDivisionError as _:
22402241
e = _
@@ -2586,9 +2587,9 @@ def exc():
25862587
try:
25872588
try:
25882589
raise EG("eg1", [ValueError(1), TypeError(2)])
2589-
except:
2590+
except EG:
25902591
raise EG("eg2", [ValueError(3), TypeError(4)])
2591-
except:
2592+
except EG:
25922593
raise ImportError(5)
25932594

25942595
expected = (
@@ -2638,7 +2639,7 @@ def exc():
26382639
except Exception as e:
26392640
exc = e
26402641
raise EG("eg", [VE(1), exc, VE(4)])
2641-
except:
2642+
except EG:
26422643
raise EG("top", [VE(5)])
26432644

26442645
expected = (f' + Exception Group Traceback (most recent call last):\n'
@@ -3451,7 +3452,7 @@ def test_long_context_chain(self):
34513452
def f():
34523453
try:
34533454
1/0
3454-
except:
3455+
except ZeroDivisionError:
34553456
f()
34563457

34573458
try:
@@ -3555,7 +3556,7 @@ def test_comparison_params_variations(self):
35553556
def raise_exc():
35563557
try:
35573558
raise ValueError('bad value')
3558-
except:
3559+
except ValueError:
35593560
raise
35603561

35613562
def raise_with_locals():

0 commit comments

Comments
 (0)
0