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 a mapping-like object to a pretty string.
  
  This class treats dataclasses as mappings where the field / field values are the keys / values.
  
  
  Args:
      mapping: The mapping object to convert.
      left_enclose_str: The string used on the left side to enclose the object. e.g. "{" for dicts or "Foo(" for
      dataclasses.
      key_value_seperator: The string used to separate keys and values. e.g. ": " for dicts, or "=" for
      dataclasses.
      right_enclose_str: The string used on the right side to enclose the object. e.g. "}" for dicts or ")" for
      dataclasses.
      is_dataclass_like_object: Flag to indicate whether this is a dataclass as there are some differences in
      formatting those.
      remaining_line_width: If specified, try to make the string representation <= this many columns wide.
  
  Returns:
      A string representation of the mapping. e.g. "{'a'=[1, 2]}" or "Foo(a=[1, 2])".
docstr_tok: ["Convert","a","mapping-like","object","to","a","pretty","string",".","This","class","treats","dataclasses","as","mappings","where","the","field","\/","field","values","are","the","keys","\/","values",".","Args",":","mapping",":","The","mapping","object","to","convert",".","left_enclose_str",":","The","string","used","on","the","left","side","to","enclose","the","object",".","e.g",".","``","{","``","for","dicts","or","``","Foo","(","``","for","dataclasses",".","key_value_seperator",":","The","string","used","to","separate","keys","and","values",".","e.g",".","``",":","``","for","dicts",",","or","``","=","''","for","dataclasses",".","right_enclose_str",":","The","string","used","on","the","right","side","to","enclose","the","object",".","e.g.","``","}","''","for","dicts","or","``",")","''","for","dataclasses",".","is_dataclass_like_object",":","Flag","to","indicate","whether","this","is","a","dataclass","as","there","are","some","differences","in","formatting","those",".","remaining_line_width",":","If","specified",",","try","to","make","the","string","representation","<","=","this","many","columns","wide",".","Returns",":","A","string","representation","of","the","mapping",".","e.g",".","``","{","'","a'=","[","1",",","2","]","}","''","or","``","Foo","(","a=","[","1",",","2","]",")","''","."]
code: def _handle_mapping_like_obj(
      self,
      mapping: Mapping,
      left_enclose_str: str,
      key_value_seperator: str,
      right_enclose_str: str,
      is_dataclass_like_object: bool,
      remaining_line_width: Optional[int],
  ) -> str:
      """Convert a mapping-like object to a pretty string.
  
      This class treats dataclasses as mappings where the field / field values are the keys / values.
  
  
      Args:
          mapping: The mapping object to convert.
          left_enclose_str: The string used on the left side to enclose the object. e.g. "{" for dicts or "Foo(" for
          dataclasses.
          key_value_seperator: The string used to separate keys and values. e.g. ": " for dicts, or "=" for
          dataclasses.
          right_enclose_str: The string used on the right side to enclose the object. e.g. "}" for dicts or ")" for
          dataclasses.
          is_dataclass_like_object: Flag to indicate whether this is a dataclass as there are some differences in
          formatting those.
          remaining_line_width: If specified, try to make the string representation <= this many columns wide.
  
      Returns:
          A string representation of the mapping. e.g. "{'a'=[1, 2]}" or "Foo(a=[1, 2])".
      """
      # Skip key / values depending on the pretty-print configuration.
      if (
          is_dataclass_like_object
          and not self._include_none_object_fields
      ):
          mapping = {
              key: value
              for key, value in mapping.items()
              if value is not None
          }
  
      if (
          is_dataclass_like_object
          and not self._include_empty_object_fields
      ):
          mapping = {
              key: value
              for key, value in mapping.items()
              if (isinstance(value, Sized) and len(value) > 0)
              or (not isinstance(value, Sized))
          }
  
      if len(mapping) == 0:
          return f"{left_enclose_str}{right_enclose_str}"
  
      # Handle case if the string representation fits on one line.
      if remaining_line_width is None or remaining_line_width > 0:
          comma_separated_items: List[str] = []
          for key, value in mapping.items():
              key_value_str_items: List[str] = []
  
              if is_dataclass_like_object:
                  if self._include_object_field_names:
                      key_value_str_items.append(str(key))
                      key_value_str_items.append(key_value_seperator)
              else:
                  key_value_str_items.append(
                      self._handle_any_obj(
                          key, remaining_line_width=None
                      )
                  )
                  key_value_str_items.append(key_value_seperator)
              key_value_str_items.append(
                  self._handle_any_obj(value, remaining_line_width=None)
              )
              comma_separated_items.append("".join(key_value_str_items))
          result_without_limit = "".join(
              (
                  left_enclose_str,
                  ", ".join(comma_separated_items),
                  right_enclose_str,
              )
          )
  
          if (
              remaining_line_width is None
              or len(result_without_limit) <= remaining_line_width
          ):
              return result_without_limit
  
      # Handle multi-line case.
      mapping_items_as_str = []
      for key, value in mapping.items():
          mapping_items_as_str.append(
              self._handle_indented_key_value_item(
                  key=key,
                  value=value,
                  key_value_seperator=key_value_seperator,
                  is_dataclass_like_object=is_dataclass_like_object,
                  remaining_line_width=(
                      remaining_line_width - len(self._indent_prefix)
                  ),
              )
          )
      lines = [
          left_enclose_str,
          ",\n".join(mapping_items_as_str) + ",",
          right_enclose_str,
      ]
      return "\n".join(lines)
  
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 5 for calling the MetricFlowPrettyFormatter obj's underlying member method code with example usage: obj._handle_mapping_like_obj(mapping, left_enclose_str, key_value_seperator, right_enclose_str, is_dataclass_like_object, remaining_line_width) and returns: str, left_enclose_str, right_enclose_str, result_without_limit