code: def can_omit_invisible_parens(
      rhs: RHSResult,
      line_length: int,
  ) -> bool:
      """Does `rhs.body` have a shape safe to reformat without optional parens around it?
  
      Returns True for only a subset of potentially nice looking formattings but
      the point is to not return false positives that end up producing lines that
      are too long.
      """
      line = rhs.body
  
      # We need optional parens in order to split standalone comments to their own lines
      # if there are no nested parens around the standalone comments
      closing_bracket: Optional[Leaf] = None
      for leaf in reversed(line.leaves):
          if (
              closing_bracket
              and leaf is closing_bracket.opening_bracket
          ):
              closing_bracket = None
          if leaf.type == STANDALONE_COMMENT and not closing_bracket:
              return False
          if (
              not closing_bracket
              and leaf.type in CLOSING_BRACKETS
              and leaf.opening_bracket in line.leaves
              and leaf.value
          ):
              closing_bracket = leaf
  
      bt = line.bracket_tracker
      if not bt.delimiters:
          # Without delimiters the optional parentheses are useless.
          return True
  
      max_priority = bt.max_delimiter_priority()
      delimiter_count = bt.delimiter_count_with_priority(max_priority)
      if delimiter_count > 1:
          # With more than one delimiter of a kind the optional parentheses read better.
          return False
  
      if delimiter_count == 1:
          if (
              Preview.wrap_multiple_context_managers_in_parens
              in line.mode
              and max_priority == COMMA_PRIORITY
              and rhs.head.is_with_or_async_with_stmt
          ):
              # For two context manager with statements, the optional parentheses read
              # better. In this case, `rhs.body` is the context managers part of
              # the with statement. `rhs.head` is the `with (` part on the previous
              # line.
              return False
          # Otherwise it may also read better, but we don't do it today and requires
          # careful considerations for all possible cases. See
          # https://github.com/psf/black/issues/2156.
  
      if max_priority == DOT_PRIORITY:
          # A single stranded method call doesn't require optional parentheses.
          return True
  
      assert len(line.leaves) >= 2, "Stranded delimiter"
  
      # With a single delimiter, omit if the expression starts or ends with
      # a bracket.
      first = line.leaves[0]
      second = line.leaves[1]
      if (
          first.type in OPENING_BRACKETS
          and second.type not in CLOSING_BRACKETS
      ):
          if _can_omit_opening_paren(
              line, first=first, line_length=line_length
          ):
              return True
  
          # Note: we are not returning False here because a line might have *both*
          # a leading opening bracket and a trailing closing bracket.  If the
          # opening bracket doesn't match our rule, maybe the closing will.
  
      penultimate = line.leaves[-2]
      last = line.leaves[-1]
  
      if (
          last.type == token.RPAR
          or last.type == token.RBRACE
          or (
              # don't use indexing for omitting optional parentheses;
              # it looks weird
              last.type == token.RSQB
              and last.parent
              and last.parent.type != syms.trailer
          )
      ):
          if penultimate.type in OPENING_BRACKETS:
              # Empty brackets don't help.
              return False
  
          if is_multiline_string(first):
              # Additional wrapping of a multiline string in this situation is
              # unnecessary.
              return True
  
          if _can_omit_closing_paren(
              line, last=last, line_length=line_length
          ):
              return True
  
      return False
  
imports: import itertools
  import math
  from dataclasses import dataclass, field
  from typing import Callable, Dict, Iterator, List, Optional, Sequence, Tuple, TypeVar, Union, cast
  from black.brackets import COMMA_PRIORITY, DOT_PRIORITY, BracketTracker
  from black.mode import Mode, Preview
  from black.nodes import BRACKETS, CLOSING_BRACKETS, OPENING_BRACKETS, STANDALONE_COMMENT, TEST_DESCENDANTS, child_towards, is_docstring, is_import, is_multiline_string, is_one_sequence_between, is_type_comment, is_type_ignore_comment, is_with_or_async_with_stmt, make_simple_prefix, replace_child, syms, whitespace
  from black.strings import str_width
  from blib2to3.pgen2 import token
  from blib2to3.pytree import Leaf, Node
label_desc: Use image node_id 5 for calling a global function with example usage: can_omit_invisible_parens(rhs, line_length) and returns: False, True, False, True, False, False, True, False, True, True