-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathutils.py
More file actions
23 lines (20 loc) · 699 Bytes
/
Copy pathutils.py
File metadata and controls
23 lines (20 loc) · 699 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
from enum import Enum
from typing import Dict
class FlattenableEnum(Enum):
"""An enumerations which can be flattened to a dictionary of strings.
This class extends the standard Enum type, adding an as_flat_dict() method
which exports the enum values to a dictionary of strings.
Example:
>>> class Color(FlattenableEnum):
... RED = 1
... GREEN = 2
... BLUE = 3
>>> Color.as_flat_dict()
{'Color.RED': '1', 'Color.GREEN': '2', 'Color.BLUE': '3'}
"""
@classmethod
def as_flat_dict(cls) -> Dict[str, str]:
res = {}
for item in cls:
res[str(item)] = str(item.value)
return res