mirror of
https://github.com/ArchipelagoMW/Archipelago.git
synced 2026-08-06 02:36:14 -07:00
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:
+9
-8
@@ -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)
|
||||
|
||||
Reference in New Issue
Block a user