From eddc5d6524865611d55b414dde34bfb6b0ae05d9 Mon Sep 17 00:00:00 2001 From: Fabian Dill Date: Fri, 1 Apr 2022 00:47:50 +0200 Subject: [PATCH] Options: some more typing --- Options.py | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/Options.py b/Options.py index 7e98f04c..025cb0d5 100644 --- a/Options.py +++ b/Options.py @@ -58,7 +58,6 @@ T = typing.TypeVar('T') class Option(typing.Generic[T], metaclass=AssembleOptions): value: T - name_lookup: typing.Dict[int, str] default = 0 # convert option_name_long into Name Long as display_name, otherwise name_long is the result. @@ -68,6 +67,10 @@ class Option(typing.Generic[T], metaclass=AssembleOptions): # can be weighted between selections supports_weighting = True + # filled by AssembleOptions: + name_lookup: typing.Dict[int, str] + options: typing.Dict[str, int] + def __repr__(self) -> str: return f"{self.__class__.__name__}({self.get_current_option_name()})" @@ -83,13 +86,13 @@ class Option(typing.Generic[T], metaclass=AssembleOptions): return self.get_option_name(self.value) @classmethod - def get_option_name(cls, value: typing.Any) -> str: + def get_option_name(cls, value: T) -> str: if cls.auto_display_name: return cls.name_lookup[value].replace("_", " ").title() else: return cls.name_lookup[value] - def __int__(self) -> int: + def __int__(self) -> T: return self.value def __bool__(self) -> bool: