Skip to content

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

Open

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?

Activity

  1. Deepwalker commented on Jun 6, 2017

    @Deepwalker
    Owner

    I think this is ok. Want to do PR?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

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