code: def safeformat(obj: object) -> str:
      """Return a pretty printed string for the given object.
  
      Failing __repr__ functions of user instances will be represented
      with a short exception info.
      """
      try:
          return pprint.pformat(obj)
      except Exception as exc:
          return _format_repr_exception(exc, obj)
  
file_path: pytest/src/_pytest/_io/saferepr.py
imports: import pprint
  import reprlib
  from typing import Optional
label_desc: Use image node_id 4 for calling a global function with example usage: safeformat(obj) and returns: pprint, _format_repr_exception