Options: some more typing

This commit is contained in:
Fabian Dill 2022-04-01 00:47:50 +02:00 committed by Fabian Dill
parent fae3068c25
commit eddc5d6524
1 changed files with 6 additions and 3 deletions

View File

@ -58,7 +58,6 @@ T = typing.TypeVar('T')
class Option(typing.Generic[T], metaclass=AssembleOptions): class Option(typing.Generic[T], metaclass=AssembleOptions):
value: T value: T
name_lookup: typing.Dict[int, str]
default = 0 default = 0
# convert option_name_long into Name Long as display_name, otherwise name_long is the result. # 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 # can be weighted between selections
supports_weighting = True supports_weighting = True
# filled by AssembleOptions:
name_lookup: typing.Dict[int, str]
options: typing.Dict[str, int]
def __repr__(self) -> str: def __repr__(self) -> str:
return f"{self.__class__.__name__}({self.get_current_option_name()})" 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) return self.get_option_name(self.value)
@classmethod @classmethod
def get_option_name(cls, value: typing.Any) -> str: def get_option_name(cls, value: T) -> str:
if cls.auto_display_name: if cls.auto_display_name:
return cls.name_lookup[value].replace("_", " ").title() return cls.name_lookup[value].replace("_", " ").title()
else: else:
return cls.name_lookup[value] return cls.name_lookup[value]
def __int__(self) -> int: def __int__(self) -> T:
return self.value return self.value
def __bool__(self) -> bool: def __bool__(self) -> bool: