Skip to content

Commit e7f642d

Browse files
committed
Docs: Update ExceptionGroup instantiations to use a tuple of exceptions instead of a static list
1 parent ef51a7c commit e7f642d

File tree

3 files changed

+10
-10
lines changed

3 files changed

+10
-10
lines changed

Doc/library/exceptions.rst

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1048,7 +1048,7 @@ their subgroups based on the types of the contained exceptions.
10481048
... def derive(self, excs):
10491049
... return MyGroup(self.message, excs)
10501050
...
1051-
>>> e = MyGroup("eg", [ValueError(1), TypeError(2)])
1051+
>>> e = MyGroup("eg", (ValueError(1), TypeError(2)))
10521052
>>> e.add_note("a note")
10531053
>>> e.__context__ = Exception("context")
10541054
>>> e.__cause__ = Exception("cause")
@@ -1059,7 +1059,7 @@ their subgroups based on the types of the contained exceptions.
10591059
...
10601060
>>> match, rest = exc.split(ValueError)
10611061
>>> exc, exc.__context__, exc.__cause__, exc.__notes__
1062-
(MyGroup('eg', [ValueError(1), TypeError(2)]), Exception('context'), Exception('cause'), ['a note'])
1062+
(MyGroup('eg', (ValueError(1), TypeError(2))), Exception('context'), Exception('cause'), ['a note'])
10631063
>>> match, match.__context__, match.__cause__, match.__notes__
10641064
(MyGroup('eg', [ValueError(1)]), Exception('context'), Exception('cause'), ['a note'])
10651065
>>> rest, rest.__context__, rest.__cause__, rest.__notes__

Doc/reference/compound_stmts.rst

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -361,7 +361,7 @@ is merged with any exceptions that were raised or re-raised from within
361361

362362
>>> try:
363363
... raise ExceptionGroup("eg",
364-
... [ValueError(1), TypeError(2), OSError(3), OSError(4)])
364+
... (ValueError(1), TypeError(2), OSError(3), OSError(4)))
365365
... except* TypeError as e:
366366
... print(f'caught {type(e)} with nested {e.exceptions}')
367367
... except* OSError as e:
@@ -372,7 +372,7 @@ is merged with any exceptions that were raised or re-raised from within
372372
+ Exception Group Traceback (most recent call last):
373373
| File "<doctest default[0]>", line 2, in <module>
374374
| raise ExceptionGroup("eg",
375-
| [ValueError(1), TypeError(2), OSError(3), OSError(4)])
375+
| (ValueError(1), TypeError(2), OSError(3), OSError(4)))
376376
| ExceptionGroup: eg (1 sub-exception)
377377
+-+---------------- 1 ----------------
378378
| ValueError: 1

Doc/tutorial/errors.rst

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -525,12 +525,12 @@ tasks may have failed in parallel, but there are also other use cases where
525525
it is desirable to continue execution and collect multiple errors rather than
526526
raise the first exception.
527527

528-
The builtin :exc:`ExceptionGroup` wraps a list of exception instances so
528+
The builtin :exc:`ExceptionGroup` wraps a sequence of exception instances so
529529
that they can be raised together. It is an exception itself, so it can be
530530
caught like any other exception. ::
531531

532532
>>> def f():
533-
... excs = [OSError('error 1'), SystemError('error 2')]
533+
... excs = (OSError('error 1'), SystemError('error 2'))
534534
... raise ExceptionGroup('there were problems', excs)
535535
...
536536
>>> f()
@@ -564,17 +564,17 @@ other clauses and eventually to be reraised. ::
564564
>>> def f():
565565
... raise ExceptionGroup(
566566
... "group1",
567-
... [
567+
... (
568568
... OSError(1),
569569
... SystemError(2),
570570
... ExceptionGroup(
571571
... "group2",
572-
... [
572+
... (
573573
... OSError(3),
574574
... RecursionError(4)
575-
... ]
575+
... )
576576
... )
577-
... ]
577+
... )
578578
... )
579579
...
580580
>>> try:

0 commit comments

Comments
 (0)