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

Function pretty_repr

rich/pretty.py:878–915  ·  view source on GitHub ↗

Prettify repr string by expanding on to new lines to fit within a given width. Args: _object (Any): Object to repr. max_width (int, optional): Desired maximum width of repr string. Defaults to 80. indent_size (int, optional): Number of spaces to indent. Defaults to 4.

(
    _object: Any,
    *,
    max_width: int = 80,
    indent_size: int = 4,
    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

876
877
878def pretty_repr(
879 _object: Any,
880 *,
881 max_width: int = 80,
882 indent_size: int = 4,
883 max_length: Optional[int] = None,
884 max_string: Optional[int] = None,
885 max_depth: Optional[int] = None,
886 expand_all: bool = False,
887) -> str:
888 """Prettify repr string by expanding on to new lines to fit within a given width.
889
890 Args:
891 _object (Any): Object to repr.
892 max_width (int, optional): Desired maximum width of repr string. Defaults to 80.
893 indent_size (int, optional): Number of spaces to indent. Defaults to 4.
894 max_length (int, optional): Maximum length of containers before abbreviating, or None for no abbreviation.
895 Defaults to None.
896 max_string (int, optional): Maximum length of string before truncating, or None to disable truncating.
897 Defaults to None.
898 max_depth (int, optional): Maximum depth of nested data structure, or None for no depth.
899 Defaults to None.
900 expand_all (bool, optional): Expand all containers regardless of available width. Defaults to False.
901
902 Returns:
903 str: A possibly multi-line representation of the object.
904 """
905
906 if _safe_isinstance(_object, Node):
907 node = _object
908 else:
909 node = traverse(
910 _object, max_length=max_length, max_string=max_string, max_depth=max_depth
911 )
912 repr_str: str = node.render(
913 max_width=max_width, indent_size=indent_size, expand_all=expand_all
914 )
915 return repr_str
916
917
918def pprint(

Calls 3

_safe_isinstanceFunction · 0.85
traverseFunction · 0.85
renderMethod · 0.45