@@ -140,11 +140,11 @@ The module defines the following functions:
140
140
141
141
Format the exception part of a traceback using an exception value such as
142
142
given by ``sys.last_value ``. The return value is a list of strings, each
143
- ending in a newline. Normally, the list contains a single string; however,
144
- for :exc: `SyntaxError ` exceptions, it contains several lines that (when
145
- printed) display detailed information about where the syntax error occurred.
146
- The message indicating which exception occurred is the always last string in
147
- the list .
143
+ ending in a newline. The list contains the exception's message, which is
144
+ normally a single string; however, for :exc: `SyntaxError ` exceptions, it
145
+ contains several lines that (when printed) display detailed information
146
+ about where the syntax error occurred. Following the message, the list
147
+ contains the exception's :attr: ` notes <BaseException.__notes__> ` .
148
148
149
149
Since Python 3.10, instead of passing *value *, an exception object
150
150
can be passed as the first argument. If *value * is provided, the first
@@ -154,6 +154,9 @@ The module defines the following functions:
154
154
The *etype * parameter has been renamed to *exc * and is now
155
155
positional-only.
156
156
157
+ .. versionchanged :: 3.11
158
+ The returned list now includes any notes attached to the exception.
159
+
157
160
158
161
.. function :: format_exception(exc, /[, value, tb], limit=None, chain=True)
159
162
@@ -236,6 +239,12 @@ capture data for later printing in a lightweight fashion.
236
239
group's exceptions array. The formatted output is truncated when either
237
240
limit is exceeded.
238
241
242
+ .. versionchanged :: 3.10
243
+ Added the *compact * parameter.
244
+
245
+ .. versionchanged :: 3.11
246
+ Added the *max_group_width * and *max_group_depth * parameters.
247
+
239
248
.. attribute :: __cause__
240
249
241
250
A :class: `TracebackException ` of the original ``__cause__ ``.
@@ -331,28 +340,20 @@ capture data for later printing in a lightweight fashion.
331
340
some containing internal newlines. :func: `~traceback.print_exception `
332
341
is a wrapper around this method which just prints the lines to a file.
333
342
334
- The message indicating which exception occurred is always the last
335
- string in the output.
336
-
337
343
.. method :: format_exception_only()
338
344
339
345
Format the exception part of the traceback.
340
346
341
347
The return value is a generator of strings, each ending in a newline.
342
348
343
- Normally, the generator emits a single string; however, for
344
- :exc: `SyntaxError ` exceptions, it emits several lines that (when
345
- printed) display detailed information about where the syntax
346
- error occurred.
347
-
348
9AC3
- The message indicating which exception occurred is always the last
349
- string in the output.
349
+ The generator emits the exception's message followed by its notes
350
+ (if it has any). The exception message is normally a single string;
351
+ however, for :exc: `SyntaxError ` exceptions, it consists of several
352
+ lines that (when printed) display detailed information about where
353
+ the syntax error occurred.
350
354
351
- .. versionchanged :: 3.10
352
- Added the *compact * parameter.
353
-
354
- .. versionchanged :: 3.11
355
- Added the *max_group_width * and *max_group_depth * parameters.
355
+ .. versionchanged :: 3.11
356
+ The exception's notes are now included in the output.
356
357
357
358
358
359
:class: `StackSummary ` Objects
0 commit comments