MCPcopy Index your code
hub / github.com/ipython/ipython / format_exception

Method format_exception

IPython/core/doctb.py:254–277  ·  view source on GitHub ↗
(self, etype: Any, evalue: Any)

Source from the content-addressed store, hash-verified

252 return head
253
254 def format_exception(self, etype: Any, evalue: Any) -> Any:
255 # Get (safely) a string form of the exception info
256 try:
257 etype_str, evalue_str = map(str, (etype, evalue))
258 except:
259 # User exception is improperly defined.
260 etype, evalue = str, sys.exc_info()[:2]
261 etype_str, evalue_str = map(str, (etype, evalue))
262
263 # PEP-678 notes
264 notes = getattr(evalue, "__notes__", [])
265 if not isinstance(notes, Sequence) or isinstance(notes, (str, bytes)):
266 notes = [_safe_string(notes, "__notes__", func=repr)]
267
268 # ... and format it
269 return [
270 theme_table[self._theme_name].format(
271 [(Token.ExcName, etype_str), (Token, ": "), (Token, evalue_str)]
272 ),
273 *(
274 theme_table[self._theme_name].format([(Token, _safe_string(n, "note"))])
275 for n in notes
276 ),
277 ]
278
279 def format_exception_as_a_whole(
280 self,

Callers 3

repr_failureMethod · 0.45

Calls 2

_safe_stringFunction · 0.85
formatMethod · 0.45

Tested by 1

repr_failureMethod · 0.36