Shortcut syntax for choices with same label & data#526
Merged
ftm merged 2 commits intopallets-eco:masterfrom Dec 17, 2019
Merged
Shortcut syntax for choices with same label & data#526ftm merged 2 commits intopallets-eco:masterfrom
ftm merged 2 commits intopallets-eco:masterfrom
Conversation
This would allow for a convenient shortcut syntax for entering choices. If label and data are both the same, you can do ['One', 'Two', 'Three'] instead of [('One', 'One'), ('Two', 'Two'), ('Three', 'Three')]
Contributor
|
Your PR is failing the style check part of the CI. WTForms uses the Black code style. If this is still something you're interested in having included into WTForms please fix the code style. |
Looks like it just deleted a little bit of whitespace
Contributor
|
Thanks for sorting that, I'll merge it now |
This was referenced Apr 18, 2020
azmeuk
added a commit
to azmeuk/wtforms
that referenced
this pull request
Apr 20, 2020
|
I am afraid there is a bug in it.. If the result is empty, the choices are effectively set to So the following lines produce some |
def iter_choices(self):
if isinstance(self.choices[0], (list, tuple)):
choices = self.choices
else:
choices = zip(self.choices, self.choices)
for value, label in choices:
yield (value, label, self.coerce(value) == self.data)It is possible to restore the original functionality by introducing some def iter_choices(self):
if self.choices:
if isinstance(self.choices[0], (list, tuple)):
choices = self.choices
else:
choices = zip(self.choices, self.choices)
for value, label in choices:
yield (value, label, self.coerce(value) == self.data)I am not sure if it is too dirty for a fix, please also note #572 😄 |
spookey
added a commit
to spookey/observatory
that referenced
this pull request
Apr 23, 2020
…move it when merging this branch back. pallets-eco/wtforms#526 (comment)
This was referenced May 16, 2020
AdrianVollmer
added a commit
to AdrianVollmer/Crack-O-Matic
that referenced
this pull request
Apr 10, 2021
The behavior of the SelectField changed in 2.3.0. We can't use the shortcut syntax with v2.2.0. And python3-wtforms on Debian 10 Bullseye is < 2.3.0. See pallets-eco/wtforms#526.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
This would allow for a convenient shortcut syntax for entering choices. If label and data are both the same, you can do
['One', 'Two', 'Three']instead of[('One', 'One'), ('Two', 'Two'), ('Three', 'Three')]