diff --git a/python/builtins.py b/python/builtins.py index a906ddf6..104ab3d7 100644 --- a/python/builtins.py +++ b/python/builtins.py @@ -239,6 +239,11 @@ class set: if not isinstance(other, set): return NotImplemented return len(self ^ other) == 0 + + def __ne__(self, other): + if not isinstance(other, set): + return NotImplemented + return len(self ^ other) != 0 def isdisjoint(self, other): return len(self & other) == 0 diff --git a/python/cmath.py b/python/cmath.py index 1d796d82..d45b9ec4 100644 --- a/python/cmath.py +++ b/python/cmath.py @@ -30,6 +30,12 @@ class complex: return self.real == other and self.imag == 0 return NotImplemented + def __ne__(self, other): + res = self == other + if res is NotImplemented: + return res + return not res + def __add__(self, other): if type(other) is complex: return complex(self.real + other.real, self.imag + other.imag) diff --git a/python/datetime.py b/python/datetime.py index e7ad4f4c..ce5a35ed 100644 --- a/python/datetime.py +++ b/python/datetime.py @@ -10,12 +10,12 @@ class timedelta: return f"datetime.timedelta(days={self.days}, seconds={self.seconds})" def __eq__(self, other: 'timedelta') -> bool: - if type(other) is not timedelta: + if not isinstance(other, timedelta): return NotImplemented return (self.days, self.seconds) == (other.days, other.seconds) def __ne__(self, other: 'timedelta') -> bool: - if type(other) is not timedelta: + if not isinstance(other, timedelta): return NotImplemented return (self.days, self.seconds) != (other.days, other.seconds)