class_docstr: Creates string representations of objects useful for logging / snapshots.
class_docstr_tok: ["Creates","string","representations","of","objects","useful","for","logging","\/","snapshots","."]
docstr: Convert any object into a pretty string-representation.
  
  This is called recursively as sequences and mappings have constituent objects of any type.
  
  Args:
      obj: The object to convert.
      remaining_line_width: If specified, try to make the string representation <= this many columns wide.
  
  Returns:
      A pretty string-representation of the object.
docstr_tok: ["Convert","any","object","into","a","pretty","string-representation",".","This","is","called","recursively","as","sequences","and","mappings","have","constituent","objects","of","any","type",".","Args",":","obj",":","The","object","to","convert",".","remaining_line_width",":","If","specified",",","try","to","make","the","string","representation","<","=","this","many","columns","wide",".","Returns",":","A","pretty","string-representation","of","the","object","."]
code: def _handle_any_obj(self, obj: Any, remaining_line_width: Optional[int]) -> str:  # type: ignore
      """Convert any object into a pretty string-representation.
  
      This is called recursively as sequences and mappings have constituent objects of any type.
  
      Args:
          obj: The object to convert.
          remaining_line_width: If specified, try to make the string representation <= this many columns wide.
  
      Returns:
          A pretty string-representation of the object.
      """
      if isinstance(obj, Enum):
          return obj.name
  
      if isinstance(obj, (list, tuple)):
          return self._handle_sequence_obj(
              obj, remaining_line_width=remaining_line_width
          )
  
      if isinstance(obj, dict):
          return self._handle_mapping_like_obj(
              obj,
              left_enclose_str="{",
              key_value_seperator=": ",
              right_enclose_str="}",
              is_dataclass_like_object=False,
              remaining_line_width=remaining_line_width,
          )
  
      if is_dataclass(obj):
          # dataclasses.asdict() seems to exclude None fields, so doing this instead.
          mapping = {
              field.name: getattr(obj, field.name)
              for field in fields(obj)
          }
          return self._handle_mapping_like_obj(
              mapping,
              left_enclose_str=type(obj).__name__ + "(",
              key_value_seperator="=",
              right_enclose_str=")",
              is_dataclass_like_object=True,
              remaining_line_width=remaining_line_width,
          )
  
      if MetricFlowPrettyFormatter._is_pydantic_base_model(obj):
          mapping = {
              key: getattr(obj, key) for key in obj.dict().keys()
          }
          return self._handle_mapping_like_obj(
              mapping,
              left_enclose_str=type(obj).__name__ + "(",
              key_value_seperator="=",
              right_enclose_str=")",
              is_dataclass_like_object=True,
              remaining_line_width=remaining_line_width,
          )
  
      # Any other object that's not handled.
      return pprint.pformat(
          obj, width=self._max_line_width, sort_dicts=False
      )
  
file_path: metricflow/metricflow/mf_logging/pretty_print.py
imports: from __future__ import annotations
  import logging
  import pprint
  from collections.abc import Mapping
  from dataclasses import fields, is_dataclass
  from enum import Enum
  from typing import Any, Dict, List, Optional, Sized, Union
  from pydantic import BaseModel
  from metricflow.mf_logging.formatting import indent
label_desc: Use image node_id 6 for calling the MetricFlowPrettyFormatter obj's underlying member method code with example usage: obj._handle_any_obj(obj, remaining_line_width) and returns: pprint, obj, self, self, self, self