You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
This repository has been archived by the owner on Oct 19, 2022. It is now read-only.
We try to use the same serializer for loading and dumping, and some of our internal objects are simple dicts with string fields, and we are forced to manually convert strings to enums or load our internal entities by schema in order to dump them. We would like to be able to
class ImageOsTypeEnum(str, Enum):
linux = 'linux'
windows = 'windows'
class OpenstackKeypairListSerializer(Schema):
os_type = EnumField(ImageOsTypeEnum, required=False)
OpenstackKeypairListSerializer().dump({'os_type': 'linux'})
without converting 'linux' to enum beforehand.
We could use OneOf and Str, but Enums are much more readable and work great with type hints.
The text was updated successfully, but these errors were encountered:
Wouldn't that API change violate type safety? i.e. silently letting 'linux' be used in place ImageOsTypeEnum.linux even though it violates the spec since it has the wrong type? If you want to have static contraints on what strings a value can take (at the level of static) there is also the new Literal type...
Personally, I don't use enums for type safety, I use them for valid value set restriction, so I don't see a problem here. Python's vision of the fact that 'linux' is not the same as ImageOsTypeEnum.linux is a language implementation detail for me.
You can always hide this feature under some kind of optional field flag.
Sign up for freeto subscribe to this conversation on GitHub.
Already have an account?
Sign in.
We try to use the same serializer for loading and dumping, and some of our internal objects are simple dicts with string fields, and we are forced to manually convert strings to enums or load our internal entities by schema in order to dump them. We would like to be able to
without converting 'linux' to enum beforehand.
We could use OneOf and Str, but Enums are much more readable and work great with type hints.
The text was updated successfully, but these errors were encountered: