-
Notifications
You must be signed in to change notification settings - Fork 1.5k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Allow io manager keys to be str enums not just strs #18778
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -2,9 +2,9 @@ | |
import re | ||
import string | ||
from collections import namedtuple | ||
from enum import Enum | ||
from enum import Enum, auto | ||
from typing import AbstractSet, Any, Dict, List, Mapping, NamedTuple, Optional, Sequence | ||
|
||
from strenum import LowercaseStrEnum | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. instead of taking this extra dep, I think we can test the same thing by just doing [1]
https://github.com/irgeek/StrEnum/blob/master/strenum/__init__.py#L21C15-L21C29 |
||
import pydantic | ||
import pytest | ||
from dagster._check import ParameterCheckError, inst_param, set_param | ||
|
@@ -180,6 +180,19 @@ class Corge(Enum): | |
assert deserialized == Corge.FOO_FOO | ||
|
||
|
||
|
||
def test_str_enum_serialization_deserialisation(): | ||
""" | ||
Checks that (de)serializing an StrEnum from the strenum lib does not produces any error and returns the string value of the enum | ||
""" | ||
class MyStrEnum(LowercaseStrEnum): | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. [1]
|
||
ONE_STR_ENUM = auto() | ||
|
||
enum_val = MyStrEnum.ONE_STR_ENUM | ||
serialized_value = serialize_value(val=enum_val) | ||
assert serialized_value == f'"{enum_val.value}"' | ||
assert deserialize_value(serialized_value) == enum_val.value | ||
|
||
def test_backward_compat_serdes(): | ||
test_map = WhitelistMap.create() | ||
|
||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@smackesey thoughts on this fallback behavior? The trade-off here is some risk in having in our code a str Enum accidentally does not get whitelisted deserializing as a normal
str
for the upside of allowing users to use str Enums in apis that accept str.