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

Function _ipy_display_hook

rich/pretty.py:113–158  ·  view source on GitHub ↗
(
    value: Any,
    console: Optional["Console"] = None,
    overflow: "OverflowMethod" = "ignore",
    crop: bool = False,
    indent_guides: bool = False,
    max_length: Optional[int] = None,
    max_string: Optional[int] = None,
    max_depth: Optional[int] = None,
    expand_all: bool = False,
)

Source from the content-addressed store, hash-verified

111
112
113def _ipy_display_hook(
114 value: Any,
115 console: Optional["Console"] = None,
116 overflow: "OverflowMethod" = "ignore",
117 crop: bool = False,
118 indent_guides: bool = False,
119 max_length: Optional[int] = None,
120 max_string: Optional[int] = None,
121 max_depth: Optional[int] = None,
122 expand_all: bool = False,
123) -> Union[str, None]:
124 # needed here to prevent circular import:
125 from .console import ConsoleRenderable
126
127 # always skip rich generated jupyter renderables or None values
128 if _safe_isinstance(value, JupyterRenderable) or value is None:
129 return None
130
131 console = console or get_console()
132
133 with console.capture() as capture:
134 # certain renderables should start on a new line
135 if _safe_isinstance(value, ConsoleRenderable):
136 console.line()
137 console.print(
138 (
139 value
140 if _safe_isinstance(value, RichRenderable)
141 else Pretty(
142 value,
143 overflow=overflow,
144 indent_guides=indent_guides,
145 max_length=max_length,
146 max_string=max_string,
147 max_depth=max_depth,
148 expand_all=expand_all,
149 margin=12,
150 )
151 ),
152 crop=crop,
153 new_line_start=True,
154 end="",
155 )
156 # strip trailing newline, not usually part of a text repr
157 # I'm not sure if this should be prevented at a lower level
158 return capture.get().rstrip("\n")
159
160
161def _safe_isinstance(

Calls 8

get_consoleFunction · 0.90
_safe_isinstanceFunction · 0.85
PrettyClass · 0.85
captureMethod · 0.80
printMethod · 0.80
rstripMethod · 0.80
lineMethod · 0.45
getMethod · 0.45