Options: use isinstance instead of type for Choice comparison
This commit is contained in:
parent
fd6e009c4b
commit
d859cecffb
17
Options.py
17
Options.py
|
@ -148,17 +148,28 @@ class Choice(Option):
|
||||||
return cls.from_text(str(data))
|
return cls.from_text(str(data))
|
||||||
|
|
||||||
def __eq__(self, other):
|
def __eq__(self, other):
|
||||||
if type(other) == str:
|
if isinstance(other, str):
|
||||||
assert other in self.options
|
assert other in self.options
|
||||||
return other == self.current_key
|
return other == self.current_key
|
||||||
elif type(other) == int:
|
elif isinstance(other, int):
|
||||||
assert other in self.name_lookup
|
assert other in self.name_lookup
|
||||||
return other == self.value
|
return other == self.value
|
||||||
elif type(other) == bool:
|
elif isinstance(other, bool):
|
||||||
return other == bool(self.value)
|
return other == bool(self.value)
|
||||||
else:
|
else:
|
||||||
raise TypeError(f"Can't compare {self.__class__.__name__} with {other.__class__.__name__}")
|
raise TypeError(f"Can't compare {self.__class__.__name__} with {other.__class__.__name__}")
|
||||||
|
|
||||||
|
def __ne__(self, other):
|
||||||
|
if isinstance(other, str):
|
||||||
|
assert other in self.options
|
||||||
|
return other != self.current_key
|
||||||
|
elif isinstance(other, int):
|
||||||
|
assert other in self.name_lookup
|
||||||
|
return other != self.value
|
||||||
|
elif isinstance(other, bool):
|
||||||
|
return other != bool(self.value)
|
||||||
|
else:
|
||||||
|
raise TypeError(f"Can't compare {self.__class__.__name__} with {other.__class__.__name__}")
|
||||||
|
|
||||||
class Range(Option, int):
|
class Range(Option, int):
|
||||||
range_start = 0
|
range_start = 0
|
||||||
|
|
Loading…
Reference in New Issue