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

Method structured_traceback

IPython/core/ultratb.py:151–241  ·  view source on GitHub ↗

Return a color formatted string with the traceback info. Parameters ---------- etype : exception type Type of the exception raised. evalue : object Data stored in the exception etb : list | TracebackType | None If list: Lis

(
        self,
        etype: type,
        evalue: Optional[BaseException],
        etb: Optional[TracebackType] = None,
        tb_offset: Optional[int] = None,
        context: int = 5,
    )

Source from the content-addressed store, hash-verified

149 return None
150
151 def structured_traceback(
152 self,
153 etype: type,
154 evalue: Optional[BaseException],
155 etb: Optional[TracebackType] = None,
156 tb_offset: Optional[int] = None,
157 context: int = 5,
158 ) -> list[str]:
159 """Return a color formatted string with the traceback info.
160
161 Parameters
162 ----------
163 etype : exception type
164 Type of the exception raised.
165 evalue : object
166 Data stored in the exception
167 etb : list | TracebackType | None
168 If list: List of frames, see class docstring for details.
169 If Traceback: Traceback of the exception.
170 tb_offset : int, optional
171 Number of frames in the traceback to skip. If not given, the
172 instance evalue is used (set in constructor).
173 context : int, optional
174 Number of lines of context information to print.
175
176 Returns
177 -------
178 String with formatted exception.
179 """
180 # This is a workaround to get chained_exc_ids in recursive calls
181 # etb should not be a tuple if structured_traceback is not recursive
182 if isinstance(etb, tuple):
183 etb, chained_exc_ids = etb
184 else:
185 chained_exc_ids = set()
186 elist: list[Any]
187 if isinstance(etb, list):
188 elist = etb
189 elif etb is not None:
190 elist = self._extract_tb(etb) # type: ignore[assignment]
191 else:
192 elist = []
193 tb_offset = self.tb_offset if tb_offset is None else tb_offset
194 assert isinstance(tb_offset, int)
195 out_list: list[str] = []
196 if elist:
197 if tb_offset and len(elist) > tb_offset:
198 elist = elist[tb_offset:]
199
200 out_list.append(
201 theme_table[self._theme_name].format(
202 [
203 (Token, "Traceback"),
204 (Token, " "),
205 (Token.NormalEm, "(most recent call last)"),
206 (Token, ":"),
207 (Token, "\n"),
208 ]

Callers 4

get_exception_onlyMethod · 0.45
structured_tracebackMethod · 0.45
structured_tracebackMethod · 0.45
structured_tracebackMethod · 0.45

Calls 7

_extract_tbMethod · 0.95
_format_listMethod · 0.95
formatMethod · 0.45
addMethod · 0.45

Tested by

no test coverage detected