Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit 26725d1

Browse filesBrowse files
[3.12] gh-125514: fix bug in test_traceback utility. Specify exception types in except: clauses (GH-125516) (#125525)
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 79422bc commit 26725d1
Copy full SHA for 26725d1

File tree

Expand file treeCollapse file tree

1 file changed

+10
-9
lines changed
Filter options
Expand file treeCollapse file tree

1 file changed

+10
-9
lines changed

‎Lib/test/test_traceback.py

Copy file name to clipboardExpand all lines: Lib/test/test_traceback.py
+10-9Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -138,7 +138,7 @@ def test_no_caret_with_no_debug_ranges_flag_python_traceback(self):
138138
import traceback
139139
try:
140140
x = 1 / 0
141-
except:
141+
except ZeroDivisionError:
142142
traceback.print_exc()
143143
""")
144144
try:
@@ -386,9 +386,10 @@ class PurePythonExceptionFormattingMixin:
386386
def get_exception(self, callable, slice_start=0, slice_end=-1):
387387
try:
388388
callable()
389-
self.fail("No exception thrown.")
390-
except:
389+
except BaseException:
391390
return traceback.format_exc().splitlines()[slice_start:slice_end]
391+
else:
392+
self.fail("No exception thrown.")
392393

393394
callable_line = get_exception.__code__.co_firstlineno + 2
394395

@@ -1490,7 +1491,7 @@ def test_context_suppression(self):
14901491
try:
14911492
try:
14921493
raise Exception
1493-
except:
1494+
except Exception:
14941495
raise ZeroDivisionError from None
14951496
except ZeroDivisionError as _:
14961497
e = _
@@ -1838,9 +1839,9 @@ def exc():
18381839
try:
18391840
try:
18401841
raise EG("eg1", [ValueError(1), TypeError(2)])
1841-
except:
1842+
except EG:
18421843
raise EG("eg2", [ValueError(3), TypeError(4)])
1843-
except:
1844+
except EG:
18441845
raise ImportError(5)
18451846

18461847
expected = (
@@ -1889,7 +1890,7 @@ def exc():
18891890
except Exception as e:
18901891
exc = e
18911892
raise EG("eg", [VE(1), exc, VE(4)])
1892-
except:
1893+
except EG:
18931894
raise EG("top", [VE(5)])
18941895

18951896
expected = (f' + Exception Group Traceback (most recent call last):\n'
@@ -2642,7 +2643,7 @@ def test_long_context_chain(self):
26422643
def f():
26432644
try:
26442645
1/0
2645-
except:
2646+
except ZeroDivisionError:
26462647
f()
26472648

26482649
try:
@@ -2731,7 +2732,7 @@ def test_comparison_params_variations(self):
27312732
def raise_exc():
27322733
try:
27332734
raise ValueError('bad value')
2734-
except:
2735+
except ValueError:
27352736
raise
27362737

27372738
def raise_with_locals():

0 commit comments

Comments
0 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.