MCPcopy
hub / github.com/Textualize/rich / _caller_frame_info

Method _caller_frame_info

rich/console.py:1909–1945  ·  view source on GitHub ↗

Get caller frame information. Args: offset (int): the caller offset within the current frame stack. currentframe (Callable[[], Optional[FrameType]], optional): the callable to use to retrieve the current frame. Defaults to None, which will use ``inspe

(
        offset: int, currentframe: Optional[Callable[[], Optional[FrameType]]] = None
    )

Source from the content-addressed store, hash-verified

1907
1908 @staticmethod
1909 def _caller_frame_info(
1910 offset: int, currentframe: Optional[Callable[[], Optional[FrameType]]] = None
1911 ) -> Tuple[str, int, Dict[str, Any]]:
1912 """Get caller frame information.
1913
1914 Args:
1915 offset (int): the caller offset within the current frame stack.
1916 currentframe (Callable[[], Optional[FrameType]], optional): the callable to use to
1917 retrieve the current frame. Defaults to None, which will use ``inspect.currentframe()``.
1918
1919 Returns:
1920 Tuple[str, int, Dict[str, Any]]: A tuple containing the filename, the line number and
1921 the dictionary of local variables associated with the caller frame.
1922
1923 Raises:
1924 RuntimeError: If the stack offset is invalid.
1925 """
1926 # Ignore the frame of this local helper
1927 offset += 1
1928
1929 if currentframe is None:
1930 import inspect
1931
1932 frame = inspect.currentframe()
1933 else:
1934 frame = currentframe()
1935 if frame is not None:
1936 while offset and frame is not None:
1937 frame = frame.f_back
1938 offset -= 1
1939 assert frame is not None
1940 return frame.f_code.co_filename, frame.f_lineno, frame.f_locals
1941 else:
1942 from inspect import stack
1943
1944 frame_info = stack()[offset]
1945 return frame_info.filename, frame_info.lineno, frame_info.frame.f_locals
1946
1947 def log(
1948 self,

Callers 2

logMethod · 0.95

Calls

no outgoing calls

Tested by 1