Repository: sympy/sympy
File: sympy/vector/vector.py (Python)

Code before:
                                  vect * measure)
        return parts

    def _div_helper(one, other):
        """ Helper for division involving vectors. """
        if isinstance(one, Vector) and isinstance(other, Vector):
            raise TypeError("Cannot divide two vectors")
        elif isinstance(one, Vector):
            if other == S.Zero:
                raise ValueError("Cannot divide a vector by zero")
            return VectorMul(one, Pow(other, S.NegativeOne))
        else:
            raise TypeError("Invalid division involving a vector")

# The following is adapted from the matrices.expressions.matexpr file

def _add_vector_postprocessor(expr: Add) -> Vector:
    return VectorAdd(*expr.args).doit(deep=False)

def _mul_vector_postprocessor(expr: Mul) -> Vector:
    return VectorMul(*expr.args).doit(deep=False)

def _pow_vector_postprocessor(expr: Pow):
    if isinstance(expr.args[0], Vector):
        raise TypeError("Power operation is not supported for vectors")
    return expr


Basic._constructor_postprocessor_mapping[Vector] = {
    "Add": [_add_vector_postprocessor],
    "Mul": [_mul_vector_postprocessor],
    "Pow": [_pow_vector_postprocessor],
}

class BaseVector(Vector, AtomicExpr):
    """
    Class to denote a base vector.

    """

    def __new__(cls, index, system, pretty_str=None, latex_str=None):
        if pretty_str is None:
            pretty_str = "x{}".format(index)
        if latex_str is None:
            latex_str = "x_{}".format(index)
        pretty_str = str(pretty_str)
        latex_str = str(latex_str)
        # Verify arguments
        if index not in range(0, 3):
            raise ValueError("index must be 0, 1 or 2")
        if not isinstance(system, CoordSys3D):

Review comment (suggestion):
It should also be an error if the second argument is a vector. I think this should just raise TypeError without any checking.

Code after:
                                  vect * measure)
        return parts

    def _div_helper(one, other):
        """ Helper for division involving vectors. """
        if isinstance(one, Vector) and isinstance(other, Vector):
            raise TypeError("Cannot divide two vectors")
        elif isinstance(one, Vector):
            if other == S.Zero:
                raise ValueError("Cannot divide a vector by zero")
            return VectorMul(one, Pow(other, S.NegativeOne))
        else:
            raise TypeError("Invalid division involving a vector")

# The following is adapted from the matrices.expressions.matexpr file

def _add_vector_postprocessor(expr: Add) -> Vector:
    return VectorAdd(*expr.args).doit(deep=False)

def _mul_vector_postprocessor(expr: Mul) -> Vector:
    return VectorMul(*expr.args).doit(deep=False)

def _pow_vector_postprocessor(expr: Pow):
    raise TypeError("Power operation is not supported for vectors")


Basic._constructor_postprocessor_mapping[Vector] = {
    "Add": [_add_vector_postprocessor],
    "Mul": [_mul_vector_postprocessor],
    "Pow": [_pow_vector_postprocessor],
}

class BaseVector(Vector, AtomicExpr):
    """
    Class to denote a base vector.

    """

    def __new__(cls, index, system, pretty_str=None, latex_str=None):
        if pretty_str is None:
            pretty_str = "x{}".format(index)
        if latex_str is None:
            latex_str = "x_{}".format(index)
        pretty_str = str(pretty_str)
        latex_str = str(latex_str)
        # Verify arguments
        if index not in range(0, 3):
            raise ValueError("index must be 0, 1 or 2")
        if not isinstance(system, CoordSys3D):
            raise TypeError("system should be a CoordSys3D")
        name = system._vector_names[index]