Skip to content

Conversation

@spumer
Copy link

@spumer spumer commented Jun 20, 2017

Fix #60 PR

Except filling rule is different. Fill from enum keys.
Cause by default enum lib support getting by key, not by value.

class MyEnum(enum.Enum):
     me = 'developer'

>>> MyEnum['me']
<MyEnum.me: 'developer'>

I think it's more clear and straightforward

@spumer
Copy link
Author

spumer commented Jun 23, 2017

@Deepwalker what do you think?


@classmethod
def _handle_variants(self, variants):
if enum is None:

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Now your code accepts not only either enum.Enum or list of enum values but also a mix of them.
I suspect t.Enum(Colors, Fruits) makes a logical mess.
Thus please make sure that variants is either a tuple with the single enum.Enum element or it doesn't contain enum.Enum items at all.
Otherwise TypeError should be raised.

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Also inline _handle_variants into constructor.
There is no need for extra method if this method is called only once. It just pollutes class namespace.


@classmethod
def _handle_variants(self, variants):
if enum is None:

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Also inline _handle_variants into constructor.
There is no need for extra method if this method is called only once. It just pollutes class namespace.

@Deepwalker
Copy link
Owner

Not sure about your keys not values approach. What do you want to check after all?
And path of trafaret is not to create big bloated classes that can work with anything. Can we create special trafaret that works with Enum classes? There is no need to this magic when you create trafaret. You know exactly what you want to check, so dont be oversmart, let people just say that they want to check Enum class, not a bunch of strings.
This is how I see it.

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

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants