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