https://dagster.io/ logo
#announcements
Title
# announcements
k

Kevin

01/06/2020, 3:20 PM
Happy new year folks! Just wanted to share this little snippet to use Python enums in solid configs and hear your thoughts on it. Is this something you already have a dedicated function for (couldn’t find anything in the docs) or something that conceptually doesn’t make sense?
Copy code
def as_dagster_enum(e: enum.EnumMeta):
    return Enum(e.__name__, [EnumValue(v.name, python_value=v) for v in e])
You can then use it in your solid config like so
Copy code
class Strategy(enum.Enum):
    SOMETHING = enum.auto()
    SOMETHING_ELSE = enum.auto()


@solid(
    config={"strategy": Field(as_dagster_enum(Strategy)),
    …
)
…
a

alex

01/06/2020, 4:11 PM
Ya this looks good - consider sending a PR to add it as a static method on
Enum
,
from_py_enum
or something
k

Kevin

01/06/2020, 10:42 PM
Done :) please let me know if anything needs improving
🤩 1