From db3ce46848b6c07a8dc76b7adb3624a9872923aa Mon Sep 17 00:00:00 2001 From: Oleh Prypin Date: Mon, 28 Oct 2024 06:49:56 -0700 Subject: [PATCH] Remove unnecessary `__ne__` fallbacks Such a fallback is already implicitly provided by Python since 3.0 https://docs.python.org/3/reference/datamodel.html#object.__ne__ PiperOrigin-RevId: 690592635 --- build_scripts/build_utils.py | 14 ++++---------- pytype/abstract/_classes.py | 3 --- pytype/abstract/_typing.py | 6 ------ pytype/pytd/booleq.py | 9 --------- pytype/pytd/pytd.py | 3 --- 5 files changed, 4 insertions(+), 31 deletions(-) diff --git a/build_scripts/build_utils.py b/build_scripts/build_utils.py index b26ab4209..79ed5ea6d 100644 --- a/build_scripts/build_utils.py +++ b/build_scripts/build_utils.py @@ -43,16 +43,10 @@ def save_to_cache_file(self): ) def __eq__(self, other): - return all([ - self.py_version == other.py_version, - self.build_type == other.build_type, - ]) - - def __ne__(self, other): - return any([ - self.py_version != other.py_version, - self.build_type != other.build_type, - ]) + return ( + self.py_version == other.py_version + and self.build_type == other.build_type + ) @classmethod def current_build_config(cls, debug): diff --git a/pytype/abstract/_classes.py b/pytype/abstract/_classes.py index 85215ccb3..bd3302d2d 100644 --- a/pytype/abstract/_classes.py +++ b/pytype/abstract/_classes.py @@ -785,9 +785,6 @@ def __eq__(self, other: "ParameterizedClass") -> bool: ) return NotImplemented - def __ne__(self, other: "ParameterizedClass") -> bool: - return not self == other - def __hash__(self): if self._hash is None: if isinstance( diff --git a/pytype/abstract/_typing.py b/pytype/abstract/_typing.py index f9a4999b2..36f1aa4d6 100644 --- a/pytype/abstract/_typing.py +++ b/pytype/abstract/_typing.py @@ -542,9 +542,6 @@ def __eq__(self, other: "_TypeVariable") -> bool: ) return NotImplemented - def __ne__(self, other: "_TypeVariable") -> bool: - return not self == other - def __hash__(self) -> int: return hash(( self.name, @@ -710,9 +707,6 @@ def __eq__(self, other: "Union") -> bool: return self.options == other.options return NotImplemented - def __ne__(self, other: "Union") -> bool: - return not self == other - def __hash__(self) -> int: # Use the names of the parameter values to approximate a hash, to avoid # infinite recursion on recursive type annotations. diff --git a/pytype/pytd/booleq.py b/pytype/pytd/booleq.py index d9173a252..e56abf18b 100644 --- a/pytype/pytd/booleq.py +++ b/pytype/pytd/booleq.py @@ -170,9 +170,6 @@ def __eq__(self, other): and self.right == other.right ) - def __ne__(self, other): - return not self == other - def simplify(self, assignments): """Simplify this equality. @@ -236,9 +233,6 @@ def __init__(self, exprs): def __eq__(self, other): return self.__class__ == other.__class__ and self.exprs == other.exprs - def __ne__(self, other): - return not self == other - def __repr__(self): return f"And({list(self.exprs)!r})" @@ -288,9 +282,6 @@ def __init__(self, exprs): def __eq__(self, other): # for unit tests return self.__class__ == other.__class__ and self.exprs == other.exprs - def __ne__(self, other): - return not self == other - def __repr__(self): return f"Or({list(self.exprs)!r})" diff --git a/pytype/pytd/pytd.py b/pytype/pytd/pytd.py index 23be32cfd..d0957b49d 100644 --- a/pytype/pytd/pytd.py +++ b/pytype/pytd/pytd.py @@ -562,9 +562,6 @@ def __eq__(self, other): return frozenset(self.type_list) == frozenset(other.type_list) return NotImplemented - def __ne__(self, other): - return not self == other - def __hash__(self): return hash(self.type_list)