Skip to content

Conversation

@shangxiao
Copy link

Closes #2839

Copy link
Contributor

Choose a reason for hiding this comment

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

I'd probably prefer to drop the indirection & just include this logic in the code as-is without the extra method.

Copy link
Author

Choose a reason for hiding this comment

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

That was actually my first attempt, although how would you inline a try/except inside a list comprehension? Was asking on #django and was told it may be possible with a generator expression & yielding?

Copy link
Contributor

Choose a reason for hiding this comment

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

Oh yup, I see that now. Missed the wrapping list comprehension.

Copy link
Contributor

Choose a reason for hiding this comment

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

Can't you just do if six.text_type(value) in self.choice_strings_to_values instead of relying on a try/except here?

(Not suggesting that we remove the extra method, just commenting on the try/except that is being used)

Copy link
Author

Choose a reason for hiding this comment

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

Actually, perhaps a self.choice_strings_to_values.get(six.text_type(value), value) is better here?

@shangxiao
Copy link
Author

@lovelydinosaur
Copy link
Contributor

Method call is simpler afterall :)

@lovelydinosaur lovelydinosaur added this to the 3.1.3 Release milestone May 15, 2015
lovelydinosaur added a commit that referenced this pull request May 15, 2015
Allow unexpected values for ChoiceField/MultipleChoiceField representations
@lovelydinosaur lovelydinosaur merged commit e33fed7 into encode:master May 15, 2015
@lovelydinosaur
Copy link
Contributor

Perfect!

@xordoquy xordoquy changed the title Allow unexpected values for ChoiceField/MultipleChoiceField representations Allow unexpected values for ChoiceField/MultipleChoiceField representations Jun 3, 2015
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Allow unexpected values for ChoiceField/MultipleChoiceField representations.

3 participants