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))
|
||||
|
||||
def __eq__(self, other):
|
||||
if type(other) == str:
|
||||
if isinstance(other, str):
|
||||
assert other in self.options
|
||||
return other == self.current_key
|
||||
elif type(other) == int:
|
||||
elif isinstance(other, int):
|
||||
assert other in self.name_lookup
|
||||
return other == self.value
|
||||
elif type(other) == bool:
|
||||
elif isinstance(other, bool):
|
||||
return other == bool(self.value)
|
||||
else:
|
||||
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):
|
||||
range_start = 0
|
||||
|
|
Loading…
Reference in New Issue