Skip to content

Commit 448eb1b

Browse files
committed
Document the 3.10-style calling pattern
1 parent 4775929 commit 448eb1b

File tree

1 file changed

+33
-16
lines changed

1 file changed

+33
-16
lines changed

shared-bindings/traceback/__init__.c

Lines changed: 33 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -104,14 +104,24 @@ STATIC void traceback_exception_common(bool is_print_exception, mp_print_t *prin
104104
}
105105

106106
//| def format_exception(
107-
//| etype: Type[BaseException],
108-
//| value: BaseException,
109-
//| tb: TracebackType,
107+
//| exc: BaseException | Type[BaseException],
108+
//| /,
109+
//| value: Optional[BaseException] = None,
110+
//| tb: Optional[TracebackType] = None,
110111
//| limit: Optional[int] = None,
111112
//| chain: Optional[bool] = True,
112-
//| ) -> None:
113+
//| ) -> str:
113114
//| """Format a stack trace and the exception information.
114115
//|
116+
//| If the exception value is passed in ``exc``, then this exception value and its
117+
//| associated traceback are used. This is compatible with CPython 3.10 and newer.
118+
//|
119+
//| If the exception value is passed in ``value``, then any value passed in for
120+
//| ``exc`` is ignored. ``value`` is used as the exception value and the
121+
//| traceback in the ``tb`` argument is used. In this case, if ``tb`` is None,
122+
//| no traceback will be shown. This is compatible with CPython 3.5 and
123+
//| newer.
124+
//|
115125
//| The arguments have the same meaning as the corresponding arguments
116126
//| to print_exception(). The return value is a list of strings, each
117127
//| ending in a newline and some containing internal newlines. When
@@ -120,15 +130,13 @@ STATIC void traceback_exception_common(bool is_print_exception, mp_print_t *prin
120130
//|
121131
//| .. note:: Setting ``chain`` will have no effect as chained exceptions are not yet implemented.
122132
//|
123-
//| :param Type[BaseException] etype: This is ignored and inferred from the type of ``value``.
124-
//| :param BaseException value: The exception. Must be an instance of `BaseException`.
125-
//| :param TracebackType tb: The traceback object. If `None`, the traceback will not be printed.
133+
//| :param exc: The exception. Must be an instance of `BaseException`. Unused if value is specified.
134+
//| :param value: If specified, is used in place of ``exc``.
135+
//| :param TracebackType tb: When value is alsp specified, ``tb`` is used in place of the exception's own traceback. If `None`, the traceback will not be printed.
126136
//| :param int limit: Print up to limit stack trace entries (starting from the caller’s frame) if limit is positive.
127137
//| Otherwise, print the last ``abs(limit)`` entries. If limit is omitted or None, all entries are printed.
128138
//| :param bool chain: If `True` then chained exceptions will be printed (note: not yet implemented).
129-
//|
130139
//| """
131-
//| ...
132140
//|
133141
STATIC mp_obj_t traceback_format_exception(size_t n_args, const mp_obj_t *pos_args, mp_map_t *kw_args) {
134142
mp_print_t print;
@@ -141,21 +149,30 @@ STATIC mp_obj_t traceback_format_exception(size_t n_args, const mp_obj_t *pos_ar
141149
STATIC MP_DEFINE_CONST_FUN_OBJ_KW(traceback_format_exception_obj, 0, traceback_format_exception);
142150

143151
//| def print_exception(
144-
//| etype: Type[BaseException],
145-
//| value: BaseException,
146-
//| tb: TracebackType,
152+
//| exc: BaseException | Type[BaseException],
153+
//| /,
154+
//| value: Optional[BaseException] = None,
155+
//| tb: Optional[TracebackType] = None,
147156
//| limit: Optional[int] = None,
148157
//| file: Optional[io.FileIO] = None,
149158
//| chain: Optional[bool] = True,
150159
//| ) -> None:
151-
//|
152160
//| """Prints exception information and stack trace entries.
153161
//|
162+
//| If the exception value is passed in ``exc``, then this exception value and its
163+
//| associated traceback are used. This is compatible with CPython 3.10 and newer.
164+
//|
165+
//| If the exception value is passed in ``value``, then any value passed in for
166+
//| ``exc`` is ignored. ``value`` is used as the exception value and the
167+
//| traceback in the ``tb`` argument is used. In this case, if ``tb`` is None,
168+
//| no traceback will be shown. This is compatible with CPython 3.5 and
169+
//| newer.
170+
//|
154171
//| .. note:: Setting ``chain`` will have no effect as chained exceptions are not yet implemented.
155172
//|
156-
//| :param Type[BaseException] etype: This is ignored and inferred from the type of ``value``.
157-
//| :param BaseException value: The exception. Must be an instance of `BaseException`.
158-
//| :param TracebackType tb: The traceback object. If `None`, the traceback will not be printed.
173+
//| :param exc: The exception. Must be an instance of `BaseException`. Unused if value is specified.
174+
//| :param value: If specified, is used in place of ``exc``.
175+
//| :param tb: When value is alsp specified, ``tb`` is used in place of the exception's own traceback. If `None`, the traceback will not be printed.
159176
//| :param int limit: Print up to limit stack trace entries (starting from the caller’s frame) if limit is positive.
160177
//| Otherwise, print the last ``abs(limit)`` entries. If limit is omitted or None, all entries are printed.
161178
//| :param io.FileIO file: If file is omitted or `None`, the output goes to `sys.stderr`; otherwise it should be an open

0 commit comments

Comments
 (0)