From 080d65c958dbdba973f0f434cbd49440e55c40b3 Mon Sep 17 00:00:00 2001 From: Dan Smith Date: Sun, 8 Sep 2024 13:26:10 -0700 Subject: [PATCH] Add deprecation warning about setting list safety --- chirp/settings.py | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/chirp/settings.py b/chirp/settings.py index 4fa49b898..1e3b1029d 100644 --- a/chirp/settings.py +++ b/chirp/settings.py @@ -14,6 +14,7 @@ # along with this program. If not, see . 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))