|
5 | 5 | import traceback |
6 | 6 | import weakref |
7 | 7 | from concurrent import futures |
8 | | -from operator import add, itemgetter |
| 8 | +from operator import add |
9 | 9 | from test import support |
10 | 10 | from test.support import Py_GIL_DISABLED |
11 | 11 |
|
@@ -60,36 +60,37 @@ def test_map_exception(self): |
60 | 60 |
|
61 | 61 | exception = None |
62 | 62 | try: |
63 | | - next(i) |
| 63 | + i.__next__() |
64 | 64 | except Exception as e: |
65 | 65 | exception = e |
66 | 66 | self.assertTrue( |
67 | 67 | isinstance(exception, ZeroDivisionError), |
68 | | - msg="next should raise a ZeroDivisionError", |
| 68 | + msg="should raise a ZeroDivisionError", |
69 | 69 | ) |
70 | 70 |
|
71 | | - # free-threading builds need this pause on Ubuntu (ARM) and Windows |
| 71 | + # pause needed for free-threading builds on Ubuntu (ARM) and Windows |
72 | 72 | time.sleep(1) |
73 | 73 |
|
74 | 74 | self.assertFalse( |
75 | 75 | gc.get_referrers(exception), |
76 | 76 | msg="the exception should not have any referrers", |
77 | 77 | ) |
78 | 78 |
|
79 | | - frames = map(itemgetter(0), traceback.walk_tb(exception.__traceback__)) |
80 | | - |
81 | | - # skip current frame |
82 | | - next(frames) |
83 | | - |
84 | 79 | self.assertFalse( |
85 | 80 | [ |
86 | 81 | (var, val) |
87 | | - for frame in frames |
| 82 | + # go through the frames of the exception's traceback |
| 83 | + for frame, _ in traceback.walk_tb(exception.__traceback__) |
| 84 | + # skipping the current frame |
| 85 | + if frame is not exception.__traceback__.tb_frame |
| 86 | + # go through the locals captured in that frame |
88 | 87 | for var, val in frame.f_locals.items() |
| 88 | + # check if one of them is an exception |
89 | 89 | if isinstance(val, Exception) |
90 | | - and frame in map(itemgetter(0), traceback.walk_tb(val.__traceback__)) |
| 90 | + # check if it is captured in its own traceback |
| 91 | + and frame is val.__traceback__.tb_frame |
91 | 92 | ], |
92 | | - msg=f"the exception's traceback should not contain an exception that captures itself in its own traceback", |
| 93 | + msg=f"the exception's traceback should not contain an exception captured in its own traceback", |
93 | 94 | ) |
94 | 95 |
|
95 | 96 | @support.requires_resource('walltime') |
|
0 commit comments