MCPcopy Index your code
hub / github.com/python/cpython / format_exception_only

Function format_exception_only

Lib/traceback.py:172–191  ·  view source on GitHub ↗

Format the exception part of a traceback. The return value is a list of strings, each ending in a newline. The list contains the exception's message, which is normally a single string; however, for :exc:`SyntaxError` exceptions, it contains several lines that (when printed) display

(exc, /, value=_sentinel, *, show_group=False, **kwargs)

Source from the content-addressed store, hash-verified

170
171
172def format_exception_only(exc, /, value=_sentinel, *, show_group=False, **kwargs):
173 """Format the exception part of a traceback.
174
175 The return value is a list of strings, each ending in a newline.
176
177 The list contains the exception's message, which is
178 normally a single string; however, for :exc:`SyntaxError` exceptions, it
179 contains several lines that (when printed) display detailed information
180 about where the syntax error occurred. Following the message, the list
181 contains the exception's ``__notes__``.
182
183 When *show_group* is ``True``, and the exception is an instance of
184 :exc:`BaseExceptionGroup`, the nested exceptions are included as
185 well, recursively, with indentation relative to their nesting depth.
186 """
187 colorize = kwargs.get("colorize", False)
188 if value is _sentinel:
189 value = exc
190 te = TracebackException(type(value), value, None, compact=True)
191 return list(te.format_exception_only(show_group=show_group, colorize=colorize))
192
193
194# -- not official API but folk probably use these two functions.

Callers 1

html_errorFunction · 0.90

Calls 4

format_exception_onlyMethod · 0.95
listClass · 0.85
TracebackExceptionClass · 0.70
getMethod · 0.45

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…