Skip to content

Commit 064b6a0

Browse files
committed
update enums
1 parent 49471cb commit 064b6a0

File tree

1 file changed

+23
-2
lines changed

1 file changed

+23
-2
lines changed

pyslurm/utils/enums.pyx

Lines changed: 23 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,9 +23,30 @@
2323
# cython: language_level=3
2424

2525
from enum import Enum, Flag
26+
import inspect
2627

28+
try:
29+
from enum import EnumMeta as EnumType
30+
except ImportError:
31+
from enum import EnumType
2732

28-
class SlurmEnum(str, Enum):
33+
34+
class DocstringSupport(EnumType):
35+
def __new__(metacls, clsname, bases, classdict):
36+
cls = super().__new__(metacls, clsname, bases, classdict)
37+
38+
# In the future, if we want to properly document enum members,
39+
# implement this:
40+
# source = inspect.getdoc(cls)
41+
# docstrings = source.replace(" ", "").split("\n")
42+
43+
for member in cls:
44+
member.__doc__ = ""
45+
46+
return cls
47+
48+
49+
class SlurmEnum(str, Enum, metaclass=DocstringSupport):
2950

3051
def __new__(cls, name, *args):
3152
# https://docs.python.org/3/library/enum.html
@@ -63,7 +84,7 @@ class SlurmEnum(str, Enum):
6384
return out
6485

6586

66-
class SlurmFlag(Flag):
87+
class SlurmFlag(Flag, metaclass=DocstringSupport):
6788

6889
def __new__(cls, flag, *args):
6990
obj = super()._new_member_(cls)

0 commit comments

Comments
 (0)