Skip to content

Re-introduce Choice and SelectChoice dataclasses#889

Merged
azmeuk merged 1 commit into
pallets-eco:mainfrom
azmeuk:choice
May 7, 2026
Merged

Re-introduce Choice and SelectChoice dataclasses#889
azmeuk merged 1 commit into
pallets-eco:mainfrom
azmeuk:choice

Conversation

@azmeuk
Copy link
Copy Markdown
Member

@azmeuk azmeuk commented Apr 23, 2026

The Choice and SelectChoice dataclasses were introduced in #739 to solve #692, but have been deleted by error in the same PR in a messy force-push.

I cherry-picked the old commit. To summarize, SelectField and RadioGroup choice parameter now take a Choice or SelectChoice instance instead of tuples. To summarize:

  • passing choices as tuples is deprecated
  • passing optgroups as a dict is deprecated
  • <option> HTML attributes can be set via Choice.render_kw
  • empty <optgroup> elements are no longer rendered
  • iter_choices return Choice instead of tuples
  • render_option takes a choice instead of value, label, selected, **kwargs

@azmeuk azmeuk added enhancement New feature, or existing feature improvement refactoring Does the same thing but in a different way labels May 5, 2026
@azmeuk azmeuk mentioned this pull request May 6, 2026
Choices can now be passed as Choice/SelectChoice instances, which
provides stronger typing, more explicit arguments and simpler code.

- passing choices as tuples is deprecated
- passing optgroups as a dict is deprecated
- <option> HTML attributes can be set via Choice.render_kw
- empty <optgroup> elements are no longer rendered
@azmeuk azmeuk merged commit fb3ca57 into pallets-eco:main May 7, 2026
17 checks passed
@azmeuk azmeuk deleted the choice branch May 7, 2026 12:32
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

enhancement New feature, or existing feature improvement refactoring Does the same thing but in a different way

Development

Successfully merging this pull request may close these issues.

Support dict for SelectForm.choices render_kw for options are not passed on correctly to _Option in SelectFieldBase.__iter__

1 participant