diff --git a/Doc/library/exceptions.rst b/Doc/library/exceptions.rst index b5e3a84b4556dd..9a14d1e26de3fe 100644 --- a/Doc/library/exceptions.rst +++ b/Doc/library/exceptions.rst @@ -1048,7 +1048,7 @@ their subgroups based on the types of the contained exceptions. ... def derive(self, excs): ... return MyGroup(self.message, excs) ... - >>> e = MyGroup("eg", [ValueError(1), TypeError(2)]) + >>> e = MyGroup("eg", (ValueError(1), TypeError(2))) >>> e.add_note("a note") >>> e.__context__ = Exception("context") >>> e.__cause__ = Exception("cause") @@ -1059,7 +1059,7 @@ their subgroups based on the types of the contained exceptions. ... >>> match, rest = exc.split(ValueError) >>> exc, exc.__context__, exc.__cause__, exc.__notes__ - (MyGroup('eg', [ValueError(1), TypeError(2)]), Exception('context'), Exception('cause'), ['a note']) + (MyGroup('eg', (ValueError(1), TypeError(2))), Exception('context'), Exception('cause'), ['a note']) >>> match, match.__context__, match.__cause__, match.__notes__ (MyGroup('eg', [ValueError(1)]), Exception('context'), Exception('cause'), ['a note']) >>> rest, rest.__context__, rest.__cause__, rest.__notes__ diff --git a/Doc/reference/compound_stmts.rst b/Doc/reference/compound_stmts.rst index 6521b4bee50758..22fd399ac6704c 100644 --- a/Doc/reference/compound_stmts.rst +++ b/Doc/reference/compound_stmts.rst @@ -361,7 +361,7 @@ is merged with any exceptions that were raised or re-raised from within >>> try: ... raise ExceptionGroup("eg", - ... [ValueError(1), TypeError(2), OSError(3), OSError(4)]) + ... (ValueError(1), TypeError(2), OSError(3), OSError(4))) ... except* TypeError as e: ... print(f'caught {type(e)} with nested {e.exceptions}') ... except* OSError as e: @@ -372,7 +372,7 @@ is merged with any exceptions that were raised or re-raised from within + Exception Group Traceback (most recent call last): | File "", line 2, in | raise ExceptionGroup("eg", - | [ValueError(1), TypeError(2), OSError(3), OSError(4)]) + | (ValueError(1), TypeError(2), OSError(3), OSError(4))) | ExceptionGroup: eg (1 sub-exception) +-+---------------- 1 ---------------- | ValueError: 1 diff --git a/Doc/tutorial/errors.rst b/Doc/tutorial/errors.rst index 1c20fa2f0b6ae5..4957b14d8cb8b7 100644 --- a/Doc/tutorial/errors.rst +++ b/Doc/tutorial/errors.rst @@ -525,12 +525,12 @@ tasks may have failed in parallel, but there are also other use cases where it is desirable to continue execution and collect multiple errors rather than raise the first exception. -The builtin :exc:`ExceptionGroup` wraps a list of exception instances so +The builtin :exc:`ExceptionGroup` wraps a sequence of exception instances so that they can be raised together. It is an exception itself, so it can be caught like any other exception. :: >>> def f(): - ... excs = [OSError('error 1'), SystemError('error 2')] + ... excs = (OSError('error 1'), SystemError('error 2')) ... raise ExceptionGroup('there were problems', excs) ... >>> f() @@ -564,17 +564,17 @@ other clauses and eventually to be reraised. :: >>> def f(): ... raise ExceptionGroup( ... "group1", - ... [ + ... ( ... OSError(1), ... SystemError(2), ... ExceptionGroup( ... "group2", - ... [ + ... ( ... OSError(3), ... RecursionError(4) - ... ] + ... ) ... ) - ... ] + ... ) ... ) ... >>> try: