Add deprecation warning about setting list safety

This commit is contained in:
Dan Smith 2024-09-08 13:26:10 -07:00 committed by Dan Smith
parent dbfaad6a6c
commit 080d65c958

View File

@ -14,6 +14,7 @@
# along with this program. If not, see <http://www.gnu.org/licenses/>.
import logging
import warnings
from chirp import chirp_common
@ -226,6 +227,14 @@ class RadioSettingValueList(RadioSettingValue):
def __init__(self, options, current=None, current_index=0):
RadioSettingValue.__init__(self)
self._options = list(options)
if current is not None:
# Using current_index is safer than using current because we can
# gracefully handle out-of-range values without crashing. All new
# code should use current_index and old code should be fixed.
warnings.warn(
'RadioSettingValueList should be provided with '
'current_index instead of current (value) for '
'safety', FutureWarning, stacklevel=2)
self.queue_current(current if current is not None
else int(current_index))