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

Function to_repr

rich/pretty.py:601–615  ·  view source on GitHub ↗

Get repr string for an object, but catch errors.

(obj: Any)

Source from the content-addressed store, hash-verified

599 """
600
601 def to_repr(obj: Any) -> str:
602 """Get repr string for an object, but catch errors."""
603 if (
604 max_string is not None
605 and _safe_isinstance(obj, (bytes, str))
606 and len(obj) > max_string
607 ):
608 truncated = len(obj) - max_string
609 obj_repr = f"{obj[:max_string]!r}+{truncated}"
610 else:
611 try:
612 obj_repr = repr(obj)
613 except Exception as error:
614 obj_repr = f"<repr-error {str(error)!r}>"
615 return obj_repr
616
617 visited_ids: Set[int] = set()
618 push_visited = visited_ids.add

Callers 1

_traverseFunction · 0.85

Calls 1

_safe_isinstanceFunction · 0.85

Tested by

no test coverage detected