From 46cfa32e04a570659a33d86953150cea51e3c257 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 | 6 ------ 5 files changed, 4 insertions(+), 34 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 13acff670..cb1eb013d 100644 --- a/pytype/abstract/_typing.py +++ b/pytype/abstract/_typing.py @@ -484,9 +484,6 @@ def __eq__(self, other): ) return NotImplemented - def __ne__(self, other): - return not self == other - def __hash__(self): return hash(( self.name, @@ -630,9 +627,6 @@ def __eq__(self, other): return self.options == other.options return NotImplemented - def __ne__(self, other): - return not self == other - def __hash__(self): # 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..f47611602 100644 --- a/pytype/pytd/pytd.py +++ b/pytype/pytd/pytd.py @@ -484,9 +484,6 @@ def IterChildren(self) -> Generator[tuple[str, Any | None], None, None]: def __eq__(self, other): return self.__class__ == other.__class__ and self.name == other.name - def __ne__(self, other): - return not self == other - def __hash__(self): return hash((self.__class__.__name__, self.name)) @@ -562,9 +559,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)