Skip to content

Commit

Permalink
annotation on anything that inherits directly from Option
Browse files Browse the repository at this point in the history
  • Loading branch information
beauxq committed Sep 13, 2023
1 parent c817dbe commit a899e92
Showing 1 changed file with 6 additions and 6 deletions.
12 changes: 6 additions & 6 deletions Options.py
Original file line number Diff line number Diff line change
Expand Up @@ -162,7 +162,7 @@ def verify(self, *args, **kwargs) -> None:
class FreeText(Option[str]):
"""Text option that allows users to enter strings.
Needs to be validated by the world or option definition."""
default = ""
default: typing.ClassVar[typing.Union[str, typing.Literal["random"]]] = ""

def __init__(self, value: str):
assert isinstance(value, str), "value of FreeText must be a string"
Expand All @@ -186,7 +186,7 @@ def get_option_name(cls, value: str) -> str:


class NumericOption(Option[int], numbers.Integral, abc.ABC):
default = 0
default: typing.ClassVar[typing.Union[int, typing.Literal["random"]]] = 0
# note: some of the `typing.Any`` here is a result of unresolved issue in python standards
# `int` is not a `numbers.Integral` according to the official typestubs
# (even though isinstance(5, numbers.Integral) == True)
Expand Down Expand Up @@ -779,7 +779,7 @@ def verify(self, world: typing.Type[World], player_name: str, plando_options: "P


class OptionDict(Option[typing.Dict[str, typing.Any]], VerifyKeys, typing.Mapping[str, typing.Any]):
default: typing.Dict[str, typing.Any] = {}
default: typing.ClassVar[typing.Dict[str, typing.Any]] = {}
supports_weighting = False

def __init__(self, value: typing.Dict[str, typing.Any]):
Expand Down Expand Up @@ -820,7 +820,7 @@ class OptionList(Option[typing.List[typing.Any]], VerifyKeys):
# If only unique entries are needed and input order of elements does not matter, OptionSet should be used instead.
# Not a docstring so it doesn't get grabbed by the options system.

default: typing.List[typing.Any] = []
default: typing.ClassVar[typing.List[typing.Any]] = []
supports_weighting = False

def __init__(self, value: typing.List[typing.Any]):
Expand All @@ -845,8 +845,8 @@ def __contains__(self, item):
return item in self.value


class OptionSet(Option[typing.Set[str]], VerifyKeys):
default: typing.Union[typing.Set[str], typing.FrozenSet[str]] = frozenset()
class OptionSet(Option[typing.AbstractSet[str]], VerifyKeys):
default: typing.ClassVar[typing.AbstractSet[str]] = frozenset()
supports_weighting = False

def __init__(self, value: typing.Iterable[str]):
Expand Down

0 comments on commit a899e92

Please sign in to comment.