mirror of
https://github.com/python/cpython.git
synced 2025-08-04 00:48:58 +00:00
[3.11] gh-103590: do not wrap a single exception raised from a try-except* (#104094)
This commit is contained in:
parent
f9231a09be
commit
5386730cdd
4 changed files with 31 additions and 25 deletions
|
@ -636,18 +636,17 @@ class TestExceptStarRaise(ExceptStarTest):
|
|||
raise orig
|
||||
except* (TypeError, ValueError) as e:
|
||||
raise SyntaxError(3)
|
||||
except BaseException as e:
|
||||
except SyntaxError as e:
|
||||
exc = e
|
||||
|
||||
self.assertExceptionIsLike(
|
||||
exc, ExceptionGroup("", [SyntaxError(3)]))
|
||||
self.assertExceptionIsLike(exc, SyntaxError(3))
|
||||
|
||||
self.assertExceptionIsLike(
|
||||
exc.exceptions[0].__context__,
|
||||
exc.__context__,
|
||||
ExceptionGroup("eg", [TypeError(1), ValueError(2)]))
|
||||
|
||||
self.assertMetadataNotEqual(orig, exc)
|
||||
self.assertMetadataEqual(orig, exc.exceptions[0].__context__)
|
||||
self.assertMetadataEqual(orig, exc.__context__)
|
||||
|
||||
def test_raise_handle_all_raise_one_unnamed(self):
|
||||
orig = ExceptionGroup("eg", [TypeError(1), ValueError(2)])
|
||||
|
@ -656,18 +655,17 @@ class TestExceptStarRaise(ExceptStarTest):
|
|||
raise orig
|
||||
except* (TypeError, ValueError) as e:
|
||||
raise SyntaxError(3)
|
||||
except ExceptionGroup as e:
|
||||
except SyntaxError as e:
|
||||
exc = e
|
||||
|
||||
self.assertExceptionIsLike(
|
||||
exc, ExceptionGroup("", [SyntaxError(3)]))
|
||||
self.assertExceptionIsLike(exc, SyntaxError(3))
|
||||
|
||||
self.assertExceptionIsLike(
|
||||
exc.exceptions[0].__context__,
|
||||
exc.__context__,
|
||||
ExceptionGroup("eg", [TypeError(1), ValueError(2)]))
|
||||
|
||||
self.assertMetadataNotEqual(orig, exc)
|
||||
self.assertMetadataEqual(orig, exc.exceptions[0].__context__)
|
||||
self.assertMetadataEqual(orig, exc.__context__)
|
||||
|
||||
def test_raise_handle_all_raise_two_named(self):
|
||||
orig = ExceptionGroup("eg", [TypeError(1), ValueError(2)])
|
||||
|
@ -791,23 +789,22 @@ class TestExceptStarRaiseFrom(ExceptStarTest):
|
|||
raise orig
|
||||
except* (TypeError, ValueError) as e:
|
||||
raise SyntaxError(3) from e
|
||||
except BaseException as e:
|
||||
except SyntaxError as e:
|
||||
exc = e
|
||||
|
||||
self.assertExceptionIsLike(
|
||||
exc, ExceptionGroup("", [SyntaxError(3)]))
|
||||
self.assertExceptionIsLike(exc, SyntaxError(3))
|
||||
|
||||
self.assertExceptionIsLike(
|
||||
exc.exceptions[0].__context__,
|
||||
exc.__context__,
|
||||
ExceptionGroup("eg", [TypeError(1), ValueError(2)]))
|
||||
|
||||
self.assertExceptionIsLike(
|
||||
exc.exceptions[0].__cause__,
|
||||
exc.__cause__,
|
||||
ExceptionGroup("eg", [TypeError(1), ValueError(2)]))
|
||||
|
||||
self.assertMetadataNotEqual(orig, exc)
|
||||
self.assertMetadataEqual(orig, exc.exceptions[0].__context__)
|
||||
self.assertMetadataEqual(orig, exc.exceptions[0].__cause__)
|
||||
self.assertMetadataEqual(orig, exc.__context__)
|
||||
self.assertMetadataEqual(orig, exc.__cause__)
|
||||
|
||||
def test_raise_handle_all_raise_one_unnamed(self):
|
||||
orig = ExceptionGroup("eg", [TypeError(1), ValueError(2)])
|
||||
|
@ -817,23 +814,22 @@ class TestExceptStarRaiseFrom(ExceptStarTest):
|
|||
except* (TypeError, ValueError) as e:
|
||||
e = sys.exception()
|
||||
raise SyntaxError(3) from e
|
||||
except ExceptionGroup as e:
|
||||
except SyntaxError as e:
|
||||
exc = e
|
||||
|
||||
self.assertExceptionIsLike(
|
||||
exc, ExceptionGroup("", [SyntaxError(3)]))
|
||||
self.assertExceptionIsLike(exc, SyntaxError(3))
|
||||
|
||||
self.assertExceptionIsLike(
|
||||
exc.exceptions[0].__context__,
|
||||
exc.__context__,
|
||||
ExceptionGroup("eg", [TypeError(1), ValueError(2)]))
|
||||
|
||||
self.assertExceptionIsLike(
|
||||
exc.exceptions[0].__cause__,
|
||||
exc.__cause__,
|
||||
ExceptionGroup("eg", [TypeError(1), ValueError(2)]))
|
||||
|
||||
self.assertMetadataNotEqual(orig, exc)
|
||||
self.assertMetadataEqual(orig, exc.exceptions[0].__context__)
|
||||
self.assertMetadataEqual(orig, exc.exceptions[0].__cause__)
|
||||
self.assertMetadataEqual(orig, exc.__context__)
|
||||
self.assertMetadataEqual(orig, exc.__cause__)
|
||||
|
||||
def test_raise_handle_all_raise_two_named(self):
|
||||
orig = ExceptionGroup("eg", [TypeError(1), ValueError(2)])
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue