@@ -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
@@ -2237,7 +2238,7 @@ def test_context_suppression(self):
2237
2238
try :
2238
2239
try :
2239
2240
raise Exception
2240
- except :
2241
+ except Exception :
2241
2242
raise ZeroDivisionError from None
2242
2243
except ZeroDivisionError as _ :
2243
2244
e = _
@@ -2589,9 +2590,9 @@ def exc():
2589
2590
try :
2590
2591
try :
2591
2592
raise EG ("eg1" , [ValueError (1 ), TypeError (2 )])
2592
- except :
2593
+ except EG :
2593
2594
raise EG ("eg2" , [ValueError (3 ), TypeError (4 )])
2594
- except :
2595
+ except EG :
2595
2596
raise ImportError (5 )
2596
2597
2597
2598
expected = (
@@ -2641,7 +2642,7 @@ def exc():
2641
2642
except Exception as e :
2642
2643
exc = e
2643
2644
raise EG ("eg" , [VE (1 ), exc , VE (4 )])
2644
- except :
2645
+ except EG :
2645
2646
raise EG ("top" , [VE (5 )])
2646
2647
2647
2648
expected = (f' + Exception Group Traceback (most recent call last):\n '
@@ -3454,7 +3455,7 @@ def test_long_context_chain(self):
3454
3455
def f ():
3455
3456
try :
3456
3457
1 / 0
3457
- except :
3458
+ except ZeroDivisionError :
3458
3459
f ()
3459
3460
3460
3461
try :
@@ -3558,7 +3559,7 @@ def test_comparison_params_variations(self):
3558
3559
def raise_exc ():
3559
3560
try :
3560
3561
raise ValueError ('bad value' )
3561
- except :
3562
+ except ValueError :
3562
3563
raise
3563
3564
3564
3565
def raise_with_locals ():
0 commit comments