Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Remove redundant total_ordering decorator usage #4203

Merged
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
revert type check change for now
  • Loading branch information
DanielYang59 committed Nov 28, 2024
commit 06abd50ff33c09b83763d0e0c890cbc43245acc4
11 changes: 6 additions & 5 deletions src/pymatgen/core/structure.py
Original file line number Diff line number Diff line change
Expand Up @@ -1097,22 +1097,23 @@ def __init__(

def __eq__(self, other: object) -> bool:
"""Define equality by comparing all three attributes: lattice, sites, properties."""
if not (hasattr(other, "lattice") and hasattr(other, "sites") and hasattr(other, "properties")):
needed_attrs = ("lattice", "sites", "properties")
if not all(hasattr(other, attr) for attr in needed_attrs):
return NotImplemented

# TODO (DanielYang59): fix below type
other = cast(Structure, other) # make mypy happy

if other is self:
return True

if isinstance(other, collections.abc.Sized) and len(self) != len(other):
if len(self) != len(other):
return False

if self.lattice != other.lattice:
return False
if self.properties != other.properties:
return False

if not isinstance(other, collections.abc.Container):
return False
return all(site in other for site in self)

def __hash__(self) -> int:
Expand Down
Loading