@@ -150,7 +150,7 @@ def test_no_caret_with_no_debug_ranges_flag_python_traceback(self):
150
150
import traceback
151
151
try:
152
152
x = 1 / 0
153
- except:
153
+ except ZeroDivisionError :
154
154
traceback.print_exc()
155
155
""" )
156
156
try :
@@ -550,9 +550,10 @@ class PurePythonExceptionFormattingMixin:
550
550
def get_exception (self , callable , slice_start = 0 , slice_end = - 1 ):
551
551
try :
552
552
callable ()
553
- self .fail ("No exception thrown." )
554
- except :
553
+ except BaseException :
555
554
return traceback .format_exc ().splitlines ()[slice_start :slice_end ]
555
+ else :
556
+ self .fail ("No exception thrown." )
556
557
557
558
callable_line = get_exception .__code__ .co_firstlineno + 2
558
559
@@ -2234,7 +2235,7 @@ def test_context_suppression(self):
2234
2235
try :
2235
2236
try :
2236
2237
raise Exception
2237
- except :
2238
+ except Exception :
2238
2239
raise ZeroDivisionError from None
2239
2240
except ZeroDivisionError as _ :
2240
2241
e = _
@@ -2586,9 +2587,9 @@ def exc():
2586
2587
try :
2587
2588
try :
2588
2589
raise EG ("eg1" , [ValueError (1 ), TypeError (2 )])
2589
- except :
2590
+ except EG :
2590
2591
raise EG ("eg2" , [ValueError (3 ), TypeError (4 )])
2591
- except :
2592
+ except EG :
2592
2593
raise ImportError (5 )
2593
2594
2594
2595
expected = (
@@ -2638,7 +2639,7 @@ def exc():
2638
2639
except Exception as e :
2639
2640
exc = e
2640
2641
raise EG ("eg" , [VE (1 ), exc , VE (4 )])
2641
- except :
2642
+ except EG :
2642
2643
raise EG ("top" , [VE (5 )])
2643
2644
2644
2645
expected = (f' + Exception Group Traceback (most recent call last):\n '
@@ -3451,7 +3452,7 @@ def test_long_context_chain(self):
3451
3452
def f ():
3452
3453
try :
3453
3454
1 / 0
3454
- except :
3455
+ except ZeroDivisionError :
3455
3456
f ()
3456
3457
3457
3458
try :
@@ -3555,7 +3556,7 @@ def test_comparison_params_variations(self):
3555
3556
def raise_exc ():
3556
3557
try :
3557
3558
raise ValueError ('bad value' )
3558
- except :
3559
+ except ValueError :
3559
3560
raise
3560
3561
3561
3562
def raise_with_locals ():
0 commit comments