From cacfd4ffae43f93b20042184cecc115ad08e05ac Mon Sep 17 00:00:00 2001 From: Aaron Wagener Date: Sun, 30 Jul 2023 18:01:21 -0500 Subject: [PATCH] Core: Add dict functionality to OptionDict (#2036) * Options: Add support for `items()` and `__getitem__` to OptionDict * Options: have OptionDict inherit from Mapping * add typing to __getitem__ Co-authored-by: black-sliver <59490463+black-sliver@users.noreply.github.com> --------- Co-authored-by: black-sliver <59490463+black-sliver@users.noreply.github.com> --- Options.py | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/Options.py b/Options.py index e106be5b..960e6c19 100644 --- a/Options.py +++ b/Options.py @@ -771,7 +771,7 @@ class VerifyKeys(metaclass=FreezeValidKeys): f"Did you mean '{picks[0][0]}' ({picks[0][1]}% sure)") -class OptionDict(Option[typing.Dict[str, typing.Any]], VerifyKeys): +class OptionDict(Option[typing.Dict[str, typing.Any]], VerifyKeys, typing.Mapping[str, typing.Any]): default: typing.Dict[str, typing.Any] = {} supports_weighting = False @@ -789,8 +789,14 @@ class OptionDict(Option[typing.Dict[str, typing.Any]], VerifyKeys): def get_option_name(self, value): return ", ".join(f"{key}: {v}" for key, v in value.items()) - def __contains__(self, item): - return item in self.value + def __getitem__(self, item: str) -> typing.Any: + return self.value.__getitem__(item) + + def __iter__(self) -> typing.Iterator[str]: + return self.value.__iter__() + + def __len__(self) -> int: + return self.value.__len__() class ItemDict(OptionDict):