Skip to content

Commit 09729f2

Browse files
committed
better gaurds on MPID comparisons
1 parent 11adec4 commit 09729f2

1 file changed

Lines changed: 7 additions & 1 deletion

File tree

emmet-core/emmet/core/mpid.py

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -91,12 +91,18 @@ def __init__(self, val: MPID | int | str) -> None:
9191
)
9292

9393
def __eq__(self, other: Any) -> bool:
94+
if other is None:
95+
return False
96+
9497
if isinstance(other, MPID):
9598
return self.string == other.string
9699
elif isinstance(other, AlphaID):
97100
return other == self
98101
elif isinstance(other, (int, str)):
99-
return self.string == MPID(other).string
102+
try:
103+
return self.string == MPID(other).string
104+
except ValueError:
105+
return False
100106
return NotImplemented
101107

102108
def __str__(self) -> str:

0 commit comments

Comments
 (0)