docstr: Collapse columns right-to-left if possible to fit table into
  max_width.
  
  If table is still too wide after collapsing, rich's automatic overflow
  handling will be used.
docstr_tok: ["Collapse","columns","right-to-left","if","possible","to","fit","table","into","max_width",".","If","table","is","still","too","wide","after","collapsing",",","rich","'s","automatic","overflow","handling","will","be","used","."]
code: def _collapse_widths(  # type: ignore[override]
      self,
      widths: List[int],
      wrapable: List[bool],
      max_width: int,
  ) -> List[int]:
      """Collapse columns right-to-left if possible to fit table into
      max_width.
  
      If table is still too wide after collapsing, rich's automatic overflow
      handling will be used.
      """
      collapsible = [column.collapse for column in self.columns]  # type: ignore[attr-defined]
      total_width = sum(widths)
      excess_width = total_width - max_width
      if any(collapsible):
          for i in range(len(widths) - 1, -1, -1):
              if collapsible[i]:
                  excess_width -= widths[i]
                  widths[i] = 0
                  if excess_width <= 0:
                      break
      return super()._collapse_widths(widths, wrapable, max_width)
  
imports: from typing import TYPE_CHECKING, Any, List
  from rich.table import Table
label_desc: Use image node_id 3 for calling the Table obj's underlying member method code with example usage: obj._collapse_widths(widths, wrapable, max_width) and returns: super