@@ -36,7 +36,8 @@ The module defines the following functions:
36
36
Added negative *limit * support.
37
37
38
38
39
- .. function :: print_exception(etype, value, tb, limit=None, file=None, chain=True)
39
+ .. function :: print_exception(exc, /[, value, tb], limit=None, \
40
+ file=None, chain=True)
40
41
41
42
Print exception information and stack trace entries from traceback object
42
43
*tb * to *file *. This differs from :func: `print_tb ` in the following
@@ -45,14 +46,18 @@ The module defines the following functions:
45
46
* if *tb * is not ``None ``, it prints a header ``Traceback (most recent
46
47
call last): ``
47
48
48
- * it prints the exception * etype * and *value * after the stack trace
49
+ * it prints the exception type and *value * after the stack trace
49
50
50
51
.. index :: single: ^ (caret); marker
51
52
52
53
* if *type(value) * is :exc: `SyntaxError ` and *value * has the appropriate
53
54
format, it prints the line where the syntax error occurred with a caret
54
55
indicating the approximate position of the error.
55
56
57
+ Since Python 3.10, instead of passing *value * and *tb *, an exception object
58
+ can be passed as the first argument. If *value * and *tb * are provided, the
59
+ first argument is ignored in order to provide backwards compatibility.
60
+
56
61
The optional *limit * argument has the same meaning as for :func: `print_tb `.
57
62
If *chain * is true (the default), then chained exceptions (the
58
63
:attr: `__cause__ ` or :attr: `__context__ ` attributes of the exception) will be
@@ -62,6 +67,10 @@ The module defines the following functions:
62
67
.. versionchanged :: 3.5
63
68
The *etype * argument is ignored and inferred from the type of *value *.
64
69
70
+ .. versionchanged :: 3.10
71
+ The *etype * parameter has been renamed to *exc * and is now
72
+ positional-only.
73
+
65
74
66
75
.. function :: print_exc(limit=None, file=None, chain=True)
67
76
@@ -121,18 +130,26 @@ The module defines the following functions:
121
130
text line is not ``None ``.
122
131
123
132
124
- .. function :: format_exception_only(etype, value)
133
+ .. function :: format_exception_only(exc, /[, value])
134
+
135
+ Format the exception part of a traceback using an exception value such as
136
+ given by ``sys.last_value ``. The return value is a list of strings, each
137
+ ending in a newline. Normally, the list contains a single string; however,
138
+ for :exc: `SyntaxError ` exceptions, it contains several lines that (when
139
+ printed) display detailed information about where the syntax error occurred.
140
+ The message indicating which exception occurred is the always last string in
141
+ the list.
125
142
126
- Format the exception part of a traceback. The arguments are the exception
127
- type and value such as given by ``sys.last_type `` and ``sys.last_value ``.
128
- The return value is a list of strings, each ending in a newline. Normally,
129
- the list contains a single string; however, for :exc: `SyntaxError `
130
- exceptions, it contains several lines that (when printed) display detailed
131
- information about where the syntax error occurred. The message indicating
132
- which exception occurred is the always last string in the list.
143
+ Since Python 3.10, instead of passing *value *, an exception object
144
+ can be passed as the first argument. If *value * is provided, the first
145
+ argument is ignored in order to provide backwards compatibility.
133
146
147
+ .. versionchanged :: 3.10
148
+ The *etype * parameter has been renamed to *exc * and is now
149
+ positional-only.
134
150
135
- .. function :: format_exception(etype, value, tb, limit=None, chain=True)
151
+
152
+ .. function :: format_exception(exc, /[, value, tb], limit=None, chain=True)
136
153
137
154
Format a stack trace and the exception information. The arguments have the
138
155
same meaning as the corresponding arguments to :func: `print_exception `. The
@@ -143,6 +160,10 @@ The module defines the following functions:
143
160
.. versionchanged :: 3.5
144
161
The *etype * argument is ignored and inferred from the type of *value *.
145
162
163
+ .. versionchanged :: 3.10
164
+ This function's behavior and signature were modified to match
165
+ :func: `print_exception `.
166
+
146
167
147
168
.. function :: format_exc(limit=None, chain=True)
148
169
0 commit comments