Skip to content

Fill t.Enum variants from Python standard library enum.Enum instances #60

@playpauseandstop

Description

@playpauseandstop

Hi.

What about adding syntax sugar for filling t.Enum variants from Python's enum.Enum? Right now it is doable, but not very reusbale,

>>> import enum
>>> import trafaret as t
>>> class PyEnum(Enum):
...    first = 'first-value'
...    second = 'second-value'
>>> trafaret = t.Enum(*(item.value for item in PyEnum.__members__.values()))
>>> trafaret.check('first-value')
'first-value'
>>> t.extract_error(trafaret, 'first')
"value doesn't match any variant"

From my POV, it'd be more user-friendly if t.Enum accepts Python enum.Enum as argument and automatically extract its values.

What do you think?

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