Options: allow comparing Choices with other Choices
This commit is contained in:
parent
e53b5324f5
commit
23b8070b9d
|
@ -150,8 +150,8 @@ class JSONtoTextParser(metaclass=HandlerMeta):
|
||||||
return "".join(self.handle_node(section) for section in input_object)
|
return "".join(self.handle_node(section) for section in input_object)
|
||||||
|
|
||||||
def handle_node(self, node: JSONMessagePart):
|
def handle_node(self, node: JSONMessagePart):
|
||||||
type = node.get("type", None)
|
node_type = node.get("type", None)
|
||||||
handler = self.handlers.get(type, self.handlers["text"])
|
handler = self.handlers.get(node_type, self.handlers["text"])
|
||||||
return handler(node)
|
return handler(node)
|
||||||
|
|
||||||
def _handle_color(self, node: JSONMessagePart):
|
def _handle_color(self, node: JSONMessagePart):
|
||||||
|
|
|
@ -150,7 +150,9 @@ class Choice(Option):
|
||||||
return cls.from_text(str(data))
|
return cls.from_text(str(data))
|
||||||
|
|
||||||
def __eq__(self, other):
|
def __eq__(self, other):
|
||||||
if isinstance(other, str):
|
if isinstance(other, self.__class__):
|
||||||
|
return other.value == self.value
|
||||||
|
elif isinstance(other, str):
|
||||||
assert other in self.options
|
assert other in self.options
|
||||||
return other == self.current_key
|
return other == self.current_key
|
||||||
elif isinstance(other, int):
|
elif isinstance(other, int):
|
||||||
|
@ -162,7 +164,9 @@ class Choice(Option):
|
||||||
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):
|
def __ne__(self, other):
|
||||||
if isinstance(other, str):
|
if isinstance(other, self.__class__):
|
||||||
|
return other.value != self.value
|
||||||
|
elif isinstance(other, str):
|
||||||
assert other in self.options
|
assert other in self.options
|
||||||
return other != self.current_key
|
return other != self.current_key
|
||||||
elif isinstance(other, int):
|
elif isinstance(other, int):
|
||||||
|
|
Loading…
Reference in New Issue