import ast


def _convert_str_to_tuple(string):
  """Function to convert a Python `str` object to a `tuple`.

  Args:
    string: The `str` to be converted.

  Returns:
    A `tuple` version of the string.

  Raises:
    ValueError: If the string is not a well formed `tuple`.
  """
  # literal_eval converts strings to int, tuple, list, float and dict,
  # booleans and None. It can also handle nested tuples.
  # It does not, however, handle elements of type set.
  try:
    value = ast.literal_eval(string)
  except ValueError:
    # A ValueError is raised by literal_eval if the string is not well
    # formed. Catch it and print out a more readable statement.
    msg = 'Argument {} does not evaluate to a `tuple` object.'.format(string)
    raise ValueError(msg)
  except SyntaxError:
    # The only other error that may be raised is a `SyntaxError` because
    # `literal_eval` calls the Python in-built `compile`. This error is
    # caused by parsing issues.
    msg = 'Error while parsing string: {}'.format(string)
    raise ValueError(msg)

  # Make sure we got a tuple. If not, its an error.
  if isinstance(value, tuple):
    return value
  else:
    raise ValueError('Expected a tuple argument, got {}'.format(type(value)))