Skip to content

Commit 55c4f4c

Browse files
authored
gh-125514: fix bug in test_traceback utility. Specify exception types in except: clauses (#125516)
1 parent c8a1818 commit 55c4f4c

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

@@ -2237,7 +2238,7 @@ def test_context_suppression(self):
22372238
try:
22382239
try:
22392240
raise Exception
2240-
except:
2241+
except Exception:
22412242
raise ZeroDivisionError from None
22422243
except ZeroDivisionError as _:
22432244
e = _
@@ -2589,9 +2590,9 @@ def exc():
25892590
try:
25902591
try:
25912592
raise EG("eg1", [ValueError(1), TypeError(2)])
2592-
except:
2593+
except EG:
25932594
raise EG("eg2", [ValueError(3), TypeError(4)])
2594-
except:
2595+
except EG:
25952596
raise ImportError(5)
25962597

25972598
expected = (
@@ -2641,7 +2642,7 @@ def exc():
26412642
except Exception as e:
26422643
exc = e
26432644
raise EG("eg", [VE(1), exc, VE(4)])
2644-
except:
2645+
except EG:
26452646
raise EG("top", [VE(5)])
26462647

26472648
expected = (f' + Exception Group Traceback (most recent call last):\n'
@@ -3454,7 +3455,7 @@ def test_long_context_chain(self):
34543455
def f():
34553456
try:
34563457
1/0
3457-
except:
3458+
except ZeroDivisionError:
34583459
f()
34593460

34603461
try:
@@ -3558,7 +3559,7 @@ def test_comparison_params_variations(self):
35583559
def raise_exc():
35593560
try:
35603561
raise ValueError('bad value')
3561-
except:
3562+
except ValueError:
35623563
raise
35633564

35643565
def raise_with_locals():

0 commit comments

Comments
 (0)