Skip to content
This repository was archived by the owner on Oct 19, 2022. It is now read-only.
This repository was archived by the owner on Oct 19, 2022. It is now read-only.

Allow dumping of non-enum value that is equal to enum's value or name #47

@Boris-Barboris

Description

@Boris-Barboris

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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions