Skip to content

Commit

Permalink
ensure value enums can be compared with strings
Browse files Browse the repository at this point in the history
  • Loading branch information
shyamd committed Jun 29, 2021
1 parent 878a91f commit 4a188af
Showing 1 changed file with 6 additions and 0 deletions.
6 changes: 6 additions & 0 deletions emmet-core/emmet/core/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -139,6 +139,12 @@ class ValueEnum(Enum):
def __str__(self):
return str(self.value)

def __eq__(self, o: object) -> bool:
"""Special Equals to enable converting strings back to the enum"""
if isinstance(o, str):
return super().__eq__(self.__class__(o))
return super().__eq__(o)


class DocEnum(ValueEnum):
"""
Expand Down

0 comments on commit 4a188af

Please sign in to comment.