def __solve_for_scalar(expr, vars):
var = solve(expr, vars).value<EOL>try:<EOL><INDENT>scalar = repeated.getvalue(var)<EOL><DEDENT>except TypeError:<EOL><INDENT>raise errors.EfilterTypeError(<EOL>root=expr, query=expr.source,<EOL>message="<STR_LIT>"<EOL>% (var,))<EOL><DEDENT>if isinstance(scalar, row_tuple.RowTuple):<EOL><INDENT>try:<EOL><INDENT>return scalar.get_singleton()<EOL><DEDENT>except ValueError:<EOL><INDENT>raise errors.EfilterTypeError(<EOL>root=expr, query=expr.source,<EOL>message="<STR_LIT>"<EOL>% (scalar,))<EOL><DEDENT><DEDENT>else:<EOL><INDENT>return scalar<EOL><DEDENT>
Helper: solve 'expr' always returning a scalar (not IRepeated).

    If the output of 'expr' is a single value or a single RowTuple with a single
    column then return the value in that column. Otherwise raise.

    Arguments:
        expr: Expression to solve.
        vars: The scope.

    Returns:
        A scalar value (not an IRepeated).

    Raises:
        EfilterTypeError if it cannot get a scalar.