Skip to content

Commit

Permalink
make MPID hashable
Browse files Browse the repository at this point in the history
  • Loading branch information
shyamd committed May 25, 2021
1 parent 4f5f85d commit 26efbd7
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 0 deletions.
3 changes: 3 additions & 0 deletions emmet-core/emmet/core/mpid.py
Expand Up @@ -54,6 +54,9 @@ def __lt__(self, other: Union["MPID", int, str]):

return self.parts < other_parts

def __hash__(self):
return hash(self.parts)

@classmethod
def __get_validators__(cls):
yield cls.validate
Expand Down
5 changes: 5 additions & 0 deletions tests/emmet-core/test_mpid.py
Expand Up @@ -11,6 +11,11 @@ def test_mpid():

assert min([MPID("mp-44545"), MPID("mp-33"), MPID("mp-2134234")]) == MPID("mp-33")

assert (
len(set([MPID("mp-33"), MPID("mp-44545"), MPID("mp-33"), MPID("mp-2134234")]))
== 3
)


def test_to_str():
assert str(MPID("mp-149")) == "mp-149"

0 comments on commit 26efbd7

Please sign in to comment.