From 43b6b4e65449b74395775a6b716a6ec887b6f929 Mon Sep 17 00:00:00 2001 From: Callum J Hays Date: Wed, 26 Oct 2022 10:26:20 +1000 Subject: [PATCH] fix: rename SumDimensionMismatch to SumDimensionMismatchError --- mathpad/val.py | 8 ++++---- mathpad/vector.py | 10 +++++----- 2 files changed, 9 insertions(+), 9 deletions(-) diff --git a/mathpad/val.py b/mathpad/val.py index 27be524..243101e 100644 --- a/mathpad/val.py +++ b/mathpad/val.py @@ -73,7 +73,7 @@ def __eq__(self, other: "Q[Self]") -> "Equation": def __eq__(self, other: "Q[Val]") -> "Equation": if isinstance(other, Val): - SumDimensionsMismatch.check(self, "==", other) + SumDimensionsMismatchError.check(self, "==", other) return Equation(self, other) def __req__(self, other: Num) -> "Equation": @@ -173,7 +173,7 @@ def in_units(self, units: Union[Literal["SI"], "Val"]) -> Self: new_units = UnitSystem.get_unit_system(units)._base_units else: - SumDimensionsMismatch.check(self, ".in_units", units) + SumDimensionsMismatchError.check(self, ".in_units", units) new_units = units.units units_factor, new_units = _split_coeff_and_units( @@ -300,7 +300,7 @@ def _sum_op( ) if isinstance(other, Val): - SumDimensionsMismatch.check( + SumDimensionsMismatchError.check( other if reverse else self, op_str, self if reverse else other ) @@ -405,7 +405,7 @@ def check(cls, exponent: Val): raise cls(f"Exponent must be dimensionless: {exponent.dimension}") -class SumDimensionsMismatch(DimensionError): +class SumDimensionsMismatchError(DimensionError): def __init__( self, left: Val, diff --git a/mathpad/vector.py b/mathpad/vector.py index 408c8e1..ccf2331 100644 --- a/mathpad/vector.py +++ b/mathpad/vector.py @@ -6,7 +6,7 @@ from sympy.vector import Dot, Vector from sympy import MatrixSymbol, Matrix, MatrixExpr, Expr, Derivative, Function -from mathpad.val import DimensionError, SumDimensionsMismatch, Val, Q +from mathpad.val import DimensionError, SumDimensionsMismatchError, Val, Q from mathpad.vector_space import VectorSpaceT from mathpad.equation import Equation @@ -68,7 +68,7 @@ def re(self, space: VectorSpaceT) -> 'Vector[VectorSpaceT]': def __eq__(self, other: 'Vector') -> "Equation": for a, b in zip(self.space.base_units, other.space.base_units): - SumDimensionsMismatch.check(a, "==", b) # type: ignore + SumDimensionsMismatchError.check(a, "==", b) # type: ignore return Equation(self, other) @@ -82,7 +82,7 @@ def __add__(self, other: Self) -> Self: f"Cannot add {type(other)} to {type(self)}" for a, b in zip(self.space.base_units, other.space.base_units): - SumDimensionsMismatch.check(a, "==", b) # type: ignore + SumDimensionsMismatchError.check(a, "==", b) # type: ignore assert self.space is other.space, \ f"Cannot add vectors of different VectorSpaces: {self.space} + {other.space}" @@ -99,7 +99,7 @@ def __sub__(self, other: Self) -> Self: "self - other" for a, b in zip(self.space.base_units, other.space.base_units): - SumDimensionsMismatch.check(a, "==", b) + SumDimensionsMismatchError.check(a, "==", b) assert self.space is other.space, \ f"Cannot subtract vectors of different VectorSpaces: {self.space} - {other.space}" @@ -171,7 +171,7 @@ def norm(self) -> Val: try: norm_squared = sum(val ** 2 for val in self) - except SumDimensionsMismatch: + except SumDimensionsMismatchError: raise ValueError("Cannot take the norm of a vector with non-uniform units") return sqrt(norm_squared) # type: ignore