def _has_balanced_parens(rhs):
  """Returns True if all '(' precede and are followed by a correspoding ')'."""
  open_parens = 0
  for token in rhs:
    for char in token:
      if char == "(":
        open_parens += 1
      elif char == ")":
        open_parens -= 1
      if open_parens < 0:
        return False
  return open_parens == 0
Returns True if all '(' precede and are followed by a correspoding ')'.
language/compgen/nqg/model/induction/induction_utils.py