Skip to content

Commit 336fbc8

Browse files
committed
update test + type check
1 parent 5c432b3 commit 336fbc8

File tree

2 files changed

+14
-4
lines changed

2 files changed

+14
-4
lines changed

spatialmath/baseposematrix.py

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1657,7 +1657,7 @@ def _op2(left, right: Self, op: Callable): # pylint: disable=no-self-argument
16571657
========= ========== ==== ================================
16581658
16591659
"""
1660-
if isinstance(right, left.__class__):
1660+
if right.__class__ is left.__class__:
16611661
# class by class
16621662
if len(left) == 1:
16631663
if len(right) == 1:
@@ -1684,7 +1684,10 @@ def _op2(left, right: Self, op: Callable): # pylint: disable=no-self-argument
16841684
else:
16851685
return [op(x, right) for x in left.A]
16861686
else:
1687-
raise ValueError(f'Invalid type ({right.__class__}) for binary operation with {left.__class__}')
1687+
raise TypeError(
1688+
f"Invalid type ({right.__class__}) for binary operation with {left.__class__}"
1689+
)
1690+
16881691

16891692
if __name__ == "__main__":
16901693
from spatialmath import SE3, SE2, SO2

tests/test_pose3d.py

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1285,10 +1285,17 @@ def test_angle(self):
12851285
p1a.angdist(other=p2a, metric=metric),
12861286
p1a.angdist(other=p2b, metric=metric),
12871287
)
1288-
# angle between mismatched types
1289-
with self.assertRaises(ValueError):
1288+
# not allowing angdist between mismatched types
1289+
with self.assertRaises(TypeError):
12901290
_ = r1.angdist(p1a)
12911291

1292+
# in general, the _op2 interface allows same type only
1293+
with self.assertRaises(TypeError):
1294+
_ = r1._op2(right=p1a, op=r1.angdist)
1295+
1296+
with self.assertRaises(TypeError):
1297+
_ = p1a._op2(right=r1, op=p1a.angdist)
1298+
12921299
def test_functions(self):
12931300
# inv
12941301
# .T

0 commit comments

Comments
 (0)