From f328ce7e7d83197f3c9273e909e381ec6475b3ec Mon Sep 17 00:00:00 2001 From: qwint Date: Tue, 4 Aug 2026 17:26:55 -0500 Subject: [PATCH] Options: add typing and remove unnecessary deepcopy call in OptionCounter (#6321) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Co-authored-by: Jérémie Bolduc <16137441+Jouramie@users.noreply.github.com> --- Options.py | 17 +++++++++-------- 1 file changed, 9 insertions(+), 8 deletions(-) diff --git a/Options.py b/Options.py index 47f4b1d45c..ed19d2eb87 100644 --- a/Options.py +++ b/Options.py @@ -938,26 +938,27 @@ class OptionCounter(OptionDict): min: int | None = None max: int | None = None cull_zeroes: bool = False + value: collections.Counter[str] def __init__(self, value: dict[str, int]) -> None: - cleaned_dict = {} + cleaned_dict = collections.Counter() invalid_value_errors = [] - for key, value in value.items(): - if not isinstance(value, (int, float)) or int(value) != value: - invalid_value_errors += [f"Invalid value {value} for key {key}, must be an integer."] + for key, subvalue in value.items(): + if not isinstance(subvalue, (int, float)) or int(subvalue) != subvalue: + invalid_value_errors += [f"Invalid value {subvalue} for key {key}, must be an integer."] continue - if self.cull_zeroes and value == 0: + if self.cull_zeroes and subvalue == 0: continue - cleaned_dict[key] = int(value) + cleaned_dict[key] = int(subvalue) if invalid_value_errors: type_errors = [f"For option {self.__class__.__name__}:"] + invalid_value_errors - raise TypeError("\n".join(invalid_value_errors)) + raise TypeError("\n".join(type_errors)) - super(OptionCounter, self).__init__(collections.Counter(cleaned_dict)) + self.value = cleaned_dict def verify(self, world: type[World], player_name: str, plando_options: PlandoOptions) -> None: super(OptionCounter, self).verify(world, player_name, plando_options)