Skip to content

Commit

Permalink
fix DocEnum
Browse files Browse the repository at this point in the history
  • Loading branch information
shyamd committed Oct 1, 2020
1 parent 971a446 commit b0e2f82
Showing 1 changed file with 9 additions and 5 deletions.
14 changes: 9 additions & 5 deletions emmet-core/emmet/core/vasp/validation.py
Expand Up @@ -5,7 +5,10 @@


class DocEnum(Enum):
"""Enum with docstrings support"""
"""
Enum with docstrings support
from: https://stackoverflow.com/a/50473952
"""

def __new__(cls, value, doc=None):
"""add docstring to the member of Enum if exists
Expand All @@ -14,10 +17,11 @@ def __new__(cls, value, doc=None):
value: Enum member value
doc: Enum member docstring, None if not exists
"""
obj = str.__new__(cls, value)
if doc:
obj.__doc__ = doc
return obj
self = object.__new__(cls) # calling super().__new__(value) here would fail
self._value_ = value
if doc is not None:
self.__doc__ = doc
return self


class DeprecationMessage(DocEnum):
Expand Down

0 comments on commit b0e2f82

Please sign in to comment.