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 Nov 3, 2024
1 parent 07f071e commit db3ce46
Show file tree
Hide file tree
Showing 5 changed files with 4 additions and 31 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 @@ -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,
Expand Down Expand Up @@ -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.
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
3 changes: 0 additions & 3 deletions pytype/pytd/pytd.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)

Expand Down

0 comments on commit db3ce46

Please sign in to comment.