MCPcopy Index your code
hub / github.com/RustPython/RustPython / format_exception_only

Method format_exception_only

Lib/traceback.py:1226–1278  ·  view source on GitHub ↗

Format the exception part of the traceback. The return value is a generator of strings, each ending in a newline. Generator yields the exception message. For :exc:`SyntaxError` exceptions, it also yields (before the exception message) several lines that (whe

(self, *, show_group=False, _depth=0, **kwargs)

Source from the content-addressed store, hash-verified

1224 return self._str
1225
1226 def format_exception_only(self, *, show_group=False, _depth=0, **kwargs):
1227 """Format the exception part of the traceback.
1228
1229 The return value is a generator of strings, each ending in a newline.
1230
1231 Generator yields the exception message.
1232 For :exc:`SyntaxError` exceptions, it
1233 also yields (before the exception message)
1234 several lines that (when printed)
1235 display detailed information about where the syntax error occurred.
1236 Following the message, generator also yields
1237 all the exception's ``__notes__``.
1238
1239 When *show_group* is ``True``, and the exception is an instance of
1240 :exc:`BaseExceptionGroup`, the nested exceptions are included as
1241 well, recursively, with indentation relative to their nesting depth.
1242 """
1243 colorize = kwargs.get("colorize", False)
1244
1245 indent = 3 * _depth * ' '
1246 if not self._have_exc_type:
1247 yield indent + _format_final_exc_line(None, self._str, colorize=colorize)
1248 return
1249
1250 stype = self.exc_type_str
1251 if not self._is_syntax_error:
1252 if _depth > 0:
1253 # Nested exceptions needs correct handling of multiline messages.
1254 formatted = _format_final_exc_line(
1255 stype, self._str, insert_final_newline=False, colorize=colorize
1256 ).split('\n')
1257 yield from [
1258 indent + l + '\n'
1259 for l in formatted
1260 ]
1261 else:
1262 yield _format_final_exc_line(stype, self._str, colorize=colorize)
1263 else:
1264 yield from [indent + l for l in self._format_syntax_error(stype, colorize=colorize)]
1265
1266 if (
1267 isinstance(self.__notes__, collections.abc.Sequence)
1268 and not isinstance(self.__notes__, (str, bytes))
1269 ):
1270 for note in self.__notes__:
1271 note = _safe_string(note, 'note')
1272 yield from [indent + l + '\n' for l in note.split('\n')]
1273 elif self.__notes__ is not None:
1274 yield indent + "{}\n".format(_safe_string(self.__notes__, '__notes__', func=repr))
1275
1276 if self.exceptions and show_group:
1277 for ex in self.exceptions:
1278 yield from ex.format_exception_only(show_group=show_group, _depth=_depth+1, colorize=colorize)
1279
1280 def _find_keyword_typos(self):
1281 assert self._is_syntax_error

Callers 15

format_exception_onlyFunction · 0.95
formatMethod · 0.80
__runMethod · 0.80
__init__Method · 0.80
user_exceptionMethod · 0.80
defaultMethod · 0.80
do_debugMethod · 0.80
_getvalMethod · 0.80
_getval_exceptMethod · 0.80
_task_print_stackFunction · 0.80
get_exception_formatMethod · 0.80
test_nocaretMethod · 0.80

Calls 7

_format_syntax_errorMethod · 0.95
_format_final_exc_lineFunction · 0.85
isinstanceFunction · 0.85
_safe_stringFunction · 0.85
getMethod · 0.45
splitMethod · 0.45
formatMethod · 0.45