Movatterモバイル変換


[0]ホーム

URL:


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

Sign up
Appearance settings

Commitc2b85a9

Browse files
authored
gh-102008: simplify test_except_star by using sys.exception() instead of sys.exc_info() (#102009)
1 parent7346a38 commitc2b85a9

File tree

1 file changed

+19
-25
lines changed

1 file changed

+19
-25
lines changed

‎Lib/test/test_except_star.py

Lines changed: 19 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -208,44 +208,38 @@ def assertMetadataNotEqual(self, e1, e2):
208208

209209
classTestExceptStarSplitSemantics(ExceptStarTest):
210210
defdoSplitTestNamed(self,exc,T,match_template,rest_template):
211-
initial_exc_info=sys.exc_info()
212-
exc_info=match=rest=None
211+
initial_sys_exception=sys.exception()
212+
sys_exception=match=rest=None
213213
try:
214214
try:
215215
raiseexc
216216
except*Tase:
217-
exc_info=sys.exc_info()
217+
sys_exception=sys.exception()
218218
match=e
219219
exceptBaseExceptionase:
220220
rest=e
221221

222-
ifmatch_template:
223-
self.assertEqual(exc_info[1],match)
224-
else:
225-
self.assertIsNone(exc_info)
222+
self.assertEqual(sys_exception,match)
226223
self.assertExceptionIsLike(match,match_template)
227224
self.assertExceptionIsLike(rest,rest_template)
228-
self.assertEqual(sys.exc_info(),initial_exc_info)
225+
self.assertEqual(sys.exception(),initial_sys_exception)
229226

230227
defdoSplitTestUnnamed(self,exc,T,match_template,rest_template):
231-
initial_exc_info=sys.exc_info()
232-
exc_info=match=rest=None
228+
initial_sys_exception=sys.exception()
229+
sys_exception=match=rest=None
233230
try:
234231
try:
235232
raiseexc
236233
except*T:
237-
exc_info=sys.exc_info()
238-
match=sys.exc_info()[1]
234+
sys_exception=match=sys.exception()
239235
else:
240236
ifrest_template:
241237
self.fail("Exception not raised")
242238
exceptBaseExceptionase:
243239
rest=e
244240
self.assertExceptionIsLike(match,match_template)
245-
ifmatch_template:
246-
self.assertEqual(exc_info[0],type(match_template))
247241
self.assertExceptionIsLike(rest,rest_template)
248-
self.assertEqual(sys.exc_info(),initial_exc_info)
242+
self.assertEqual(sys.exception(),initial_sys_exception)
249243

250244
defdoSplitTestInExceptHandler(self,exc,T,match_template,rest_template):
251245
try:
@@ -409,11 +403,11 @@ def test_multiple_matches_unnamed(self):
409403
try:
410404
raiseExceptionGroup("mmu", [OSError("os"),BlockingIOError("io")])
411405
except*BlockingIOError:
412-
e=sys.exc_info()[1]
406+
e=sys.exception()
413407
self.assertExceptionIsLike(e,
414408
ExceptionGroup("mmu", [BlockingIOError("io")]))
415409
except*OSError:
416-
e=sys.exc_info()[1]
410+
e=sys.exception()
417411
self.assertExceptionIsLike(e,
418412
ExceptionGroup("mmu", [OSError("os")]))
419413
else:
@@ -434,7 +428,7 @@ def test_first_match_wins_unnamed(self):
434428
try:
435429
raiseExceptionGroup("fstu", [BlockingIOError("io")])
436430
except*OSError:
437-
e=sys.exc_info()[1]
431+
e=sys.exception()
438432
self.assertExceptionIsLike(e,
439433
ExceptionGroup("fstu", [BlockingIOError("io")]))
440434
except*BlockingIOError:
@@ -452,7 +446,7 @@ def test_nested_except_stars(self):
452446
pass
453447
else:
454448
self.fail("Exception not raised")
455-
e=sys.exc_info()[1]
449+
e=sys.exception()
456450
self.assertExceptionIsLike(e,
457451
ExceptionGroup("n", [BlockingIOError("io")]))
458452
else:
@@ -766,7 +760,7 @@ def test_raise_unnamed(self):
766760
try:
767761
raiseorig
768762
except*OSError:
769-
e=sys.exc_info()[1]
763+
e=sys.exception()
770764
raiseTypeError(3)frome
771765
exceptExceptionGroupase:
772766
exc=e
@@ -821,7 +815,7 @@ def test_raise_handle_all_raise_one_unnamed(self):
821815
try:
822816
raiseorig
823817
except* (TypeError,ValueError)ase:
824-
e=sys.exc_info()[1]
818+
e=sys.exception()
825819
raiseSyntaxError(3)frome
826820
exceptExceptionGroupase:
827821
exc=e
@@ -882,10 +876,10 @@ def test_raise_handle_all_raise_two_unnamed(self):
882876
try:
883877
raiseorig
884878
except*TypeError:
885-
e=sys.exc_info()[1]
879+
e=sys.exception()
886880
raiseSyntaxError(3)frome
887881
except*ValueError:
888-
e=sys.exc_info()[1]
882+
e=sys.exception()
889883
raiseSyntaxError(4)frome
890884
exceptExceptionGroupase:
891885
exc=e
@@ -982,7 +976,7 @@ def derive(self, excs):
982976

983977

984978
classTestExceptStarCleanup(ExceptStarTest):
985-
deftest_exc_info_restored(self):
979+
deftest_sys_exception_restored(self):
986980
try:
987981
try:
988982
raiseValueError(42)
@@ -997,7 +991,7 @@ def test_exc_info_restored(self):
997991

998992
self.assertExceptionIsLike(exc,ZeroDivisionError('division by zero'))
999993
self.assertExceptionIsLike(exc.__context__,ValueError(42))
1000-
self.assertEqual(sys.exc_info(),(None,None,None))
994+
self.assertEqual(sys.exception(),None)
1001995

1002996

1003997
classTestExceptStar_WeirdLeafExceptions(ExceptStarTest):

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp