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

Method format_exception

IPython/core/ultratb.py:751–779  ·  view source on GitHub ↗
(self, etype, evalue)

Source from the content-addressed store, hash-verified

749 return head
750
751 def format_exception(self, etype, evalue):
752 # Get (safely) a string form of the exception info
753 try:
754 etype_str, evalue_str = map(str, (etype, evalue))
755 except:
756 # User exception is improperly defined.
757 etype, evalue = str, sys.exc_info()[:2]
758 etype_str, evalue_str = map(str, (etype, evalue))
759
760 # PEP-678 notes
761 notes = getattr(evalue, "__notes__", [])
762 if not isinstance(notes, Sequence) or isinstance(notes, (str, bytes)):
763 notes = [_safe_string(notes, "__notes__", func=repr)]
764
765 for note in notes:
766 assert isinstance(note, str)
767
768 str_notes: Sequence[str] = notes
769
770 # ... and format it
771 return [
772 theme_table[self._theme_name].format(
773 [(Token.ExcName, etype_str), (Token, ": "), (Token, evalue_str)]
774 ),
775 *(
776 theme_table[self._theme_name].format([(Token, note)])
777 for note in str_notes
778 ),
779 ]
780
781 def format_exception_as_a_whole(
782 self,

Callers 1

Calls 2

_safe_stringFunction · 0.85
formatMethod · 0.45

Tested by

no test coverage detected