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

Method format_record

IPython/core/ultratb.py:562–713  ·  view source on GitHub ↗

Format a single stack frame

(self, frame_info: FrameInfo)

Source from the content-addressed store, hash-verified

560 self.skip_hidden = True
561
562 def format_record(self, frame_info: FrameInfo) -> str:
563 """Format a single stack frame"""
564 assert isinstance(frame_info, FrameInfo)
565
566 if isinstance(frame_info._sd, stack_data.RepeatedFrames):
567 return theme_table[self._theme_name].format(
568 [
569 (Token, " "),
570 (
571 Token.ExcName,
572 "[... skipping similar frames: %s]" % frame_info.description,
573 ),
574 (Token, "\n"),
575 ]
576 )
577
578 indent: str = " " * INDENT_SIZE
579
580 assert isinstance(frame_info.lineno, int)
581 args, varargs, varkw, locals_ = inspect.getargvalues(frame_info.frame)
582 func: str
583 if frame_info.executing is not None:
584 func = frame_info.executing.code_qualname()
585 elif frame_info.code is not None:
586 func = (
587 getattr(frame_info.code, "co_qualname", None) or frame_info.code.co_name
588 )
589 else:
590 func = "?"
591 if func == "<module>":
592 call = ""
593 else:
594 # Decide whether to include variable details or not
595 var_repr = eqrepr if self.include_vars else nullrepr
596 try:
597 scope = inspect.formatargvalues(
598 args, varargs, varkw, locals_, formatvalue=var_repr
599 )
600 assert isinstance(scope, str)
601 call = theme_table[self._theme_name].format(
602 [(Token, "in "), (Token.VName, func), (Token.ValEm, scope)]
603 )
604 except KeyError:
605 # This happens in situations like errors inside generator
606 # expressions, where local variables are listed in the
607 # line, but can't be extracted from the frame. I'm not
608 # 100% sure this isn't actually a bug in inspect itself,
609 # but since there's no info for us to compute with, the
610 # best we can do is report the failure and move on. Here
611 # we must *not* call any traceback construction again,
612 # because that would mess up use of %debug later on. So we
613 # simply report the failure and move on. The only
614 # limitation will be that this frame won't have locals
615 # listed in the call signature. Quite subtle problem...
616 # I can't think of a good way to validate this in a unit
617 # test, but running a script consisting of:
618 # dict( (k,v.strip()) for (k,v) in range(10) )
619 # will illustrate the error, if this exception catch is

Callers 1

Calls 5

ParserClass · 0.90
_tokens_filenameFunction · 0.85
_format_traceback_linesFunction · 0.70
formatMethod · 0.45

Tested by

no test coverage detected