From 5ba2460f9b68959210e86d4376500cdb0c3e236e Mon Sep 17 00:00:00 2001 From: Haoyu Yang Date: Thu, 28 Nov 2024 23:09:46 +0800 Subject: [PATCH] revert type check change for now --- src/pymatgen/core/structure.py | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/src/pymatgen/core/structure.py b/src/pymatgen/core/structure.py index 895b6b729a5..0ee62619f50 100644 --- a/src/pymatgen/core/structure.py +++ b/src/pymatgen/core/structure.py @@ -1097,13 +1097,17 @@ 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: @@ -1111,8 +1115,6 @@ def __eq__(self, other: object) -> bool: 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: