mirror of
https://github.com/MarioSpore/Grinch-AP.git
synced 2025-10-21 20:21:32 -06:00
Core: Support inequality operators ("less than") for Choice option string comparisons (#3769)
* add some unit tests to it * fix * Update Options.py Co-authored-by: qwint <qwint.42@gmail.com> * Update Options.py --------- Co-authored-by: qwint <qwint.42@gmail.com>
This commit is contained in:
24
Options.py
24
Options.py
@@ -494,6 +494,30 @@ class Choice(NumericOption):
|
||||
else:
|
||||
raise TypeError(f"Can't compare {self.__class__.__name__} with {other.__class__.__name__}")
|
||||
|
||||
def __lt__(self, other: typing.Union[Choice, int, str]):
|
||||
if isinstance(other, str):
|
||||
assert other in self.options, f"compared against an unknown string. {self} < {other}"
|
||||
other = self.options[other]
|
||||
return super(Choice, self).__lt__(other)
|
||||
|
||||
def __gt__(self, other: typing.Union[Choice, int, str]):
|
||||
if isinstance(other, str):
|
||||
assert other in self.options, f"compared against an unknown string. {self} > {other}"
|
||||
other = self.options[other]
|
||||
return super(Choice, self).__gt__(other)
|
||||
|
||||
def __le__(self, other: typing.Union[Choice, int, str]):
|
||||
if isinstance(other, str):
|
||||
assert other in self.options, f"compared against an unknown string. {self} <= {other}"
|
||||
other = self.options[other]
|
||||
return super(Choice, self).__le__(other)
|
||||
|
||||
def __ge__(self, other: typing.Union[Choice, int, str]):
|
||||
if isinstance(other, str):
|
||||
assert other in self.options, f"compared against an unknown string. {self} >= {other}"
|
||||
other = self.options[other]
|
||||
return super(Choice, self).__ge__(other)
|
||||
|
||||
__hash__ = Option.__hash__ # see https://docs.python.org/3/reference/datamodel.html#object.__hash__
|
||||
|
||||
|
||||
|
Reference in New Issue
Block a user