@@ -138,7 +138,7 @@ def test_no_caret_with_no_debug_ranges_flag_python_traceback(self):
138
138
import traceback
139
139
try:
140
140
x = 1 / 0
141
- except:
141
+ except ZeroDivisionError :
142
142
traceback.print_exc()
143
143
""" )
144
144
try :
@@ -386,9 +386,10 @@ class PurePythonExceptionFormattingMixin:
386
386
def get_exception (self , callable , slice_start = 0 , slice_end = - 1 ):
387
387
try :
388
388
10000
callable ()
389
- self .fail ("No exception thrown." )
390
- except :
389
+ except BaseException :
391
390
return traceback .format_exc ().splitlines ()[slice_start :slice_end ]
391
+ else :
392
+ self .fail ("No exception thrown." )
392
393
393
394
callable_line = get_exception .__code__ .co_firstlineno + 2
394
395
@@ -1490,7 +1491,7 @@ def test_context_suppression(self):
1490
1491
try :
1491
1492
try :
1492
1493
raise Exception
1493
- except :
1494
+ except Exception :
1494
1495
raise ZeroDivisionError from None
1495
1496
except ZeroDivisionError as _ :
1496
1497
e = _
@@ -1838,9 +1839,9 @@ def exc():
1838
1839
try :
1839
1840
try :
1840
1841
raise EG ("eg1" , [ValueError (1 ), TypeError (2 )])
1841
- except :
1842
+ except EG :
1842
1843
raise EG ("eg2" , [ValueError (3 ), TypeError (4 )])
1843
- except :
1844
+ except EG :
1844
1845
raise ImportError (5 )
1845
1846
1846
1847
expected = (
@@ -1889,7 +1890,7 @@ def exc():
1889
1890
except Exception as e :
1890
1891
exc = e
1891
1892
raise EG ("eg" , [VE (1 ), exc , VE (4 )])
1892
- except :
1893
+ except EG :
1893
1894
raise EG ("top" , [VE (5 )])
1894
1895
1895
1896
expected = (f' + Exception Group Traceback (most recent call last):\n '
@@ -2642,7 +2643,7 @@ def test_long_context_chain(self):
2642
2643
def f ():
2643
2644
try :
2644
2645
1 / 0
2645
- except :
2646
+ except ZeroDivisionError :
2646
2647
f ()
2647
2648
2648
2649
try :
@@ -2731,7 +2732,7 @@ def test_comparison_params_variations(self):
2731
2732
def raise_exc ():
2732
2733
try :
2733
2734
raise ValueError ('bad value' )
2734
- except :
2735
+ except ValueError :
2735
2736
raise
2736
2737
2737
2738
def raise_with_locals ():
0 commit comments