Skip to content

Commit

Permalink
Remove unnecessary __ne__ fallbacks
Browse files Browse the repository at this point in the history
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
  • Loading branch information
oprypin authored and copybara-github committed Oct 28, 2024
1 parent 6b85e37 commit 46cfa32
Show file tree
Hide file tree
Showing 5 changed files with 4 additions and 34 deletions.
14 changes: 4 additions & 10 deletions build_scripts/build_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand Down
3 changes: 0 additions & 3 deletions pytype/abstract/_classes.py
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down
6 changes: 0 additions & 6 deletions pytype/abstract/_typing.py
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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.
Expand Down
9 changes: 0 additions & 9 deletions pytype/pytd/booleq.py
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down Expand Up @@ -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})"

Expand Down Expand Up @@ -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})"

Expand Down
6 changes: 0 additions & 6 deletions pytype/pytd/pytd.py
Original file line number Diff line number Diff line change
Expand Up @@ -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))

Expand Down Expand Up @@ -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)

Expand Down

0 comments on commit 46cfa32

Please sign in to comment.