Options: add typing and remove unnecessary deepcopy call in OptionCounter (#6321)

Co-authored-by: Jérémie Bolduc <[email protected]>
This commit is contained in:
qwint
2026-08-05 00:26:55 +02:00
committed by GitHub
co-authored by Jérémie Bolduc
parent 8b3557cd6c
commit f328ce7e7d
+9 -8
View File
@@ -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)