Skip to content

Commit 1885394

Browse files
authored
fix: deprecate RangeBearingSensor's animate kwarg instead of erroring (#599)
animate was silently renamed to plot in 68292ae/93be21f9 (2023) with no back-compat shim, so existing scripts using the old name hit an unexplained TypeError from SensorBase.__init__ instead of a clear deprecation warning. A stray comment at the old call site ("TODO change plot option to animate, but RVC3 uses plot") shows this was known and only partially addressed.
1 parent c2be132 commit 1885394

2 files changed

Lines changed: 28 additions & 1 deletion

File tree

src/roboticstoolbox/mobile/sensors.py

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
from abc import ABC
2+
import warnings
23
import numpy as np
34
import scipy as sp
45
from math import pi, sin, cos
@@ -56,6 +57,7 @@ def __init__(
5657
delay=0.1,
5758
seed=0,
5859
verbose=False,
60+
**kwargs,
5961
):
6062
"""Sensor.Sensor Sensor object constructor
6163
%
@@ -73,6 +75,12 @@ def __init__(
7375
# - Animation shows a ray from the vehicle position to the selected
7476
# landmark.
7577
"""
78+
if kwargs:
79+
raise TypeError(
80+
f"SensorBase.__init__() got unexpected keyword argument(s): "
81+
f"{', '.join(kwargs)}"
82+
)
83+
7684
self._robot = robot
7785
self._map = map
7886
self._every = every
@@ -266,9 +274,19 @@ def __init__(
266274
>>> print(sensor)
267275
268276
:seealso: :class:`~roboticstoolbox.mobile.LandmarkMap` :class:`~roboticstoolbox.mobile.EKF`
277+
278+
.. deprecated:: the ``animate`` keyword is deprecated, use ``plot``
279+
instead.
269280
"""
270281

271-
# TODO change plot option to animate, but RVC3 uses plot
282+
animate = kwargs.pop("animate", None)
283+
if animate is not None:
284+
warnings.warn(
285+
"animate is deprecated, use plot instead",
286+
DeprecationWarning,
287+
stacklevel=2,
288+
)
289+
plot = animate
272290

273291
# call the superclass constructor
274292
super().__init__(robot, map, **kwargs)

tests/test_mobile.py

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -108,6 +108,15 @@ def test_init(self):
108108

109109
self.assertIsInstance(str(self.rs), str)
110110

111+
def test_animate_deprecated(self):
112+
113+
with self.assertWarns(DeprecationWarning):
114+
rs = RangeBearingSensor(self.veh, self.map, animate=True)
115+
self.assertTrue(rs._animate)
116+
117+
with self.assertRaises(TypeError):
118+
RangeBearingSensor(self.veh, self.map, bogus_kwarg=True)
119+
111120
def test_reading(self):
112121

113122
z, lm_id = self.rs.reading()

0 commit comments

Comments
 (0)