Skip to content

Commit

Permalink
add warning when iter_choices return a 3 items tuple
Browse files Browse the repository at this point in the history
  • Loading branch information
azmeuk committed Nov 1, 2023
1 parent 9a9d1f4 commit b63b9ac
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 1 deletion.
14 changes: 14 additions & 0 deletions src/wtforms/widgets/core.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
import warnings

from markupsafe import escape
from markupsafe import Markup

Expand Down Expand Up @@ -362,6 +364,12 @@ def __call__(self, field, **kwargs):
if len(choice) == 4:
val, label, selected, render_kw = choice
else:
warnings.warn(
"'iter_groups' is expected to return 4 items tuple since "
"wtforms 3.1, this will be mandatory in wtforms 3.2",
DeprecationWarning,
stacklevel=2,
)
val, label, selected = choice
render_kw = {}
html.append(self.render_option(val, label, selected, **render_kw))
Expand All @@ -371,6 +379,12 @@ def __call__(self, field, **kwargs):
if len(choice) == 4:
val, label, selected, render_kw = choice
else:
warnings.warn(
"'iter_groups' is expected to return 4 items tuple since "
"wtforms 3.1, this will be mandatory in wtforms 3.2",
DeprecationWarning,
stacklevel=2,
)
val, label, selected = choice
render_kw = {}
html.append(self.render_option(val, label, selected, **render_kw))
Expand Down
2 changes: 1 addition & 1 deletion tests/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ def basic_widget_dummy_field(dummy_field_class):

@pytest.fixture
def select_dummy_field(dummy_field_class):
return dummy_field_class([("foo", "lfoo", True), ("bar", "lbar", False)])
return dummy_field_class([("foo", "lfoo", True, {}), ("bar", "lbar", False, {})])


@pytest.fixture
Expand Down

0 comments on commit b63b9ac

Please sign in to comment.