import sympy


def to_sympy_matrix(value):
    """
    Converts value to a `sympy.Matrix` object, if possible.
    Leaves the value as `sympy.Matrix` if it already was
    :param value: value to convert
    :return:
    :rtype: `sympy.Matrix`
    """
    if isinstance(value, sympy.Matrix):
        return value
    try:
        return sympy.Matrix(value)
    except ValueError as original_exception:
        if isinstance(value, list) and len(value) and all([not isinstance(x, list) for x in value]):
            # Let's try to convert the contents into a list
            # (this is required for 0.7.4 if we pass in a list of strings)
            # See `test_creation_of_column_matrix_from_list_of_strings` test
            list_of_lists_value = [[x] for x in value]
            try:
                m = sympy.Matrix(list_of_lists_value)
                return m
            except Exception:
                raise original_exception
        else:
            raise original_exception