-
Notifications
You must be signed in to change notification settings - Fork 24
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
trafaret/Enum: support Python >=3.4 enum
module
#67
base: master
Are you sure you want to change the base?
Conversation
@Deepwalker what do you think? |
trafaret/__init__.py
Outdated
self.variants = variants[:] | ||
|
||
@classmethod | ||
def _handle_variants(self, variants): | ||
if enum is None: |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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.
trafaret/__init__.py
Outdated
self.variants = variants[:] | ||
|
||
@classmethod | ||
def _handle_variants(self, variants): | ||
if enum is None: |
There was a problem hiding this comment.
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.
Not sure about your keys not values approach. What do you want to check after all? |
Fix #60 PR
Except filling rule is different. Fill from enum keys.
Cause by default enum lib support getting by key, not by value.
I think it's more clear and straightforward