From d859cecffbf03f70a9d214723e065e5c0cd4ef0c Mon Sep 17 00:00:00 2001 From: Fabian Dill Date: Mon, 30 Aug 2021 23:07:19 +0200 Subject: [PATCH] Options: use isinstance instead of type for Choice comparison --- Options.py | 17 ++++++++++++++--- 1 file changed, 14 insertions(+), 3 deletions(-) diff --git a/Options.py b/Options.py index 1a7faf02..f31c7e6f 100644 --- a/Options.py +++ b/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