Skip to content

Commit 33bb8db

Browse files
Merge pull request #84 from bdaiinstitute/SW-237-Fix-fallthrough-constructors-in-spatialmath
[SW-237] Raises error if a number of arguments besides 1 and 3 are passed in to SE3 constructors
2 parents c89285a + 953b893 commit 33bb8db

File tree

2 files changed

+9
-0
lines changed

2 files changed

+9
-0
lines changed

spatialmath/pose3d.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -976,6 +976,9 @@ def __init__(self, x=None, y=None, z=None, *, check=True):
976976
# SE3(x, y, z)
977977
self.data = [smb.transl(x, y, z)]
978978

979+
else:
980+
raise ValueError("Invalid arguments. See documentation for correct format.")
981+
979982
@staticmethod
980983
def _identity() -> NDArray:
981984
return np.eye(4)

tests/test_pose3d.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -833,6 +833,12 @@ def test_constructor(self):
833833
self.assertEqual(T.A.shape, (4,4))
834834
nt.assert_equal(T.t, [1, 2, 0])
835835

836+
# Bad number of arguments
837+
with self.assertRaises(ValueError):
838+
T = SE3(1.0, 0.0)
839+
with self.assertRaises(TypeError):
840+
T = SE3(1.0, 0.0, 0.0, 0.0)
841+
836842
def test_shape(self):
837843
a = SE3()
838844
self.assertEqual(a._A.shape, a.shape)

0 commit comments

Comments
 (0)