Options: allow comparing Choices with other Choices

This commit is contained in:
Fabian Dill 2021-09-04 17:53:09 +02:00
parent e53b5324f5
commit 23b8070b9d
2 changed files with 8 additions and 4 deletions

View File

@ -150,8 +150,8 @@ class JSONtoTextParser(metaclass=HandlerMeta):
return "".join(self.handle_node(section) for section in input_object)
def handle_node(self, node: JSONMessagePart):
type = node.get("type", None)
handler = self.handlers.get(type, self.handlers["text"])
node_type = node.get("type", None)
handler = self.handlers.get(node_type, self.handlers["text"])
return handler(node)
def _handle_color(self, node: JSONMessagePart):

View File

@ -150,7 +150,9 @@ class Choice(Option):
return cls.from_text(str(data))
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
return other == self.current_key
elif isinstance(other, int):
@ -162,7 +164,9 @@ class Choice(Option):
raise TypeError(f"Can't compare {self.__class__.__name__} with {other.__class__.__name__}")
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
return other != self.current_key
elif isinstance(other, int):