Repository navigation
[WTForms] Update stubs for 3.3.0 #16604
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
Merged
Merged
Changes from all commits
Commits
Show all changes
10 commits
Select commit
Hold shift + click to select a range
efe39a5
[WTForms] Update stubs for 3.3.0
Daverball 2ff3e9f
Fixes regressions
Daverball ec18d85
Adds final missing type hint
Daverball 52ed7f8
Updates choices regression tests
Daverball 9de75f7
Fixes overly-broad `_LegacyCallback` return type
Daverball a4b3df4
Apply batched suggestions from code review
Daverball ade908d
Apply suggested changes to `NumberRange`
Daverball 23ad540
Fix inconsistent widget `kwargs` types and add explanations via comments
Daverball 718e53b
Adds comment to `html_params`
Daverball 9251162
Adds missed `_RenderArg`
Daverball File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
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
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,67 +1,122 @@ | ||
| from __future__ import annotations | ||
|
|
||
| from wtforms import SelectField | ||
| from enum import Enum, auto | ||
|
|
||
| from wtforms import Field, Form, SelectChoice, SelectField, StringField | ||
| from wtforms.fields import enum_choices, enum_coerce | ||
|
|
||
| # construct SelectChoice from old inputs | ||
| SelectChoice.from_input("") | ||
| SelectChoice.from_input(("", "")) | ||
| SelectChoice.from_input(("", "", {})) | ||
| # non-str values are no longer allowed/encouraged | ||
| # technically they never were, it just never was enforced | ||
| # coerce(value) is supposed to yield the object that gets stored in data | ||
| # so values in choices are intended to be pre-serialized to str in the | ||
| # format coerce expects | ||
| SelectChoice.from_input((1, "1")) # type: ignore[arg-type] | ||
| SelectChoice.from_input((True, "t", {})) # type: ignore[arg-type] | ||
| SelectChoice.from_input((False, "f", {})) # type: ignore[arg-type] | ||
|
|
||
| # provide choices as any iterable of SelectChoice | ||
| SelectField(choices=[SelectChoice("")]) | ||
|
|
||
| # new style of grouped choices | ||
| SelectField(choices=[SelectChoice("A", optgroup="a"), SelectChoice("B", optgroup="b")]) | ||
|
|
||
| # provide a callback without arguments that generates a sequence of SelectChoice | ||
| SelectField(choices=lambda: [SelectChoice("")]) | ||
|
|
||
|
|
||
| # or a callback that receives the form as its first and the field as its second argument | ||
| def generate_choices(form: Form, field: SelectField) -> list[SelectChoice]: | ||
| return [] | ||
|
|
||
|
|
||
| def generate_choices_generous_field_type(form: Form, field: Field) -> list[SelectChoice]: | ||
| return [] | ||
|
|
||
|
|
||
| def generate_choices_wrong_field_type(form: Form, field: StringField) -> list[SelectChoice]: | ||
| return [] | ||
|
|
||
|
|
||
| SelectField(choices=lambda form, field: [SelectChoice("")]) | ||
| SelectField(choices=generate_choices) | ||
| SelectField(choices=generate_choices_generous_field_type) | ||
| SelectField(choices=generate_choices_wrong_field_type) # type: ignore | ||
|
|
||
|
|
||
| # provide choices based on enum | ||
| class TestEnum(Enum): | ||
| foo = auto() | ||
| bar = auto() | ||
| baz = auto() | ||
|
|
||
|
|
||
| SelectField(choices=enum_choices(TestEnum), coerce=enum_coerce(TestEnum)) | ||
|
|
||
| # deprecated ways of providing choices: | ||
| # any way we can specify the choices inline with a literal should work | ||
|
|
||
| # tuple of tuples | ||
| SelectField(choices=(("", ""),)) | ||
| SelectField(choices=((1, "1"),)) | ||
| SelectField(choices=(("", "", {}),)) | ||
| SelectField(choices=((True, "t", {}),)) | ||
| SelectField(choices=((True, "t"), (False, "f", {}))) | ||
| SelectField(choices=(("", ""),)) # pyright: ignore[reportDeprecated] | ||
| SelectField(choices=((1, "1"),)) # pyright: ignore[reportDeprecated] | ||
| SelectField(choices=(("", "", {}),)) # pyright: ignore[reportDeprecated] | ||
| SelectField(choices=((True, "t", {}),)) # pyright: ignore[reportDeprecated] | ||
| SelectField(choices=((True, "t"), (False, "f", {}))) # pyright: ignore[reportDeprecated] | ||
|
|
||
| # list of tuples | ||
| SelectField(choices=[("", "")]) | ||
| SelectField(choices=[(1, "1")]) | ||
| SelectField(choices=[("", "", {})]) | ||
| SelectField(choices=[(True, "t", {})]) | ||
| SelectField(choices=[(True, "t"), (False, "f", {})]) | ||
| SelectField(choices=[("", "")]) # pyright: ignore[reportDeprecated] | ||
| SelectField(choices=[(1, "1")]) # pyright: ignore[reportDeprecated] | ||
| SelectField(choices=[("", "", {})]) # pyright: ignore[reportDeprecated] | ||
| SelectField(choices=[(True, "t", {})]) # pyright: ignore[reportDeprecated] | ||
| SelectField(choices=[(True, "t"), (False, "f", {})]) # pyright: ignore[reportDeprecated] | ||
|
|
||
| # dict of tuple of tuples | ||
| SelectField(choices={"a": (("", ""),)}) | ||
| SelectField(choices={"a": ((1, "1"),)}) | ||
| SelectField(choices={"a": (("", "", {}),)}) | ||
| SelectField(choices={"a": ((True, "t", {}),)}) | ||
| SelectField(choices={"a": ((True, "t"), (False, "f", {}))}) | ||
| SelectField(choices={"a": ((True, "", {}),), "b": ((False, "f"),)}) | ||
| SelectField(choices={"a": (("", ""),)}) # pyright: ignore[reportDeprecated] | ||
| SelectField(choices={"a": ((1, "1"),)}) # pyright: ignore[reportDeprecated] | ||
| SelectField(choices={"a": (("", "", {}),)}) # pyright: ignore[reportDeprecated] | ||
| SelectField(choices={"a": ((True, "t", {}),)}) # pyright: ignore[reportDeprecated] | ||
| SelectField(choices={"a": ((True, "t"), (False, "f", {}))}) # pyright: ignore[reportDeprecated] | ||
| SelectField(choices={"a": ((True, "", {}),), "b": ((False, "f"),)}) # pyright: ignore[reportDeprecated] | ||
|
|
||
| # dict of list of tuples | ||
| SelectField(choices={"a": [("", "")]}) | ||
| SelectField(choices={"a": [(1, "1")]}) | ||
| SelectField(choices={"a": [("", "", {})]}) | ||
| SelectField(choices={"a": [(True, "t", {})]}) | ||
| SelectField(choices={"a": [(True, "t"), (False, "f", {})]}) | ||
| SelectField(choices={"a": [(True, "", {})], "b": [(False, "f")]}) | ||
| SelectField(choices={"a": [("", "")]}) # pyright: ignore[reportDeprecated] | ||
| SelectField(choices={"a": [(1, "1")]}) # pyright: ignore[reportDeprecated] | ||
| SelectField(choices={"a": [("", "", {})]}) # pyright: ignore[reportDeprecated] | ||
| SelectField(choices={"a": [(True, "t", {})]}) # pyright: ignore[reportDeprecated] | ||
| SelectField(choices={"a": [(True, "t"), (False, "f", {})]}) # pyright: ignore[reportDeprecated] | ||
| SelectField(choices={"a": [(True, "", {})], "b": [(False, "f")]}) # pyright: ignore[reportDeprecated] | ||
|
|
||
| # the same should be true for lambdas | ||
|
|
||
| # tuple of tuples | ||
| SelectField(choices=lambda: (("", ""),)) | ||
| SelectField(choices=lambda: ((1, "1"),)) | ||
| SelectField(choices=lambda: (("", "", {}),)) | ||
| SelectField(choices=lambda: ((True, "t", {}),)) | ||
| SelectField(choices=lambda: ((True, "t"), (False, "f", {}))) | ||
| SelectField(choices=lambda: (("", ""),)) # pyright: ignore[reportDeprecated] | ||
| SelectField(choices=lambda: ((1, "1"),)) # pyright: ignore[reportDeprecated] | ||
| SelectField(choices=lambda: (("", "", {}),)) # pyright: ignore[reportDeprecated] | ||
| SelectField(choices=lambda: ((True, "t", {}),)) # pyright: ignore[reportDeprecated] | ||
| SelectField(choices=lambda: ((True, "t"), (False, "f", {}))) # pyright: ignore[reportDeprecated] | ||
|
|
||
| # list of tuples | ||
| SelectField(choices=lambda: [("", "")]) | ||
| SelectField(choices=lambda: [(1, "1")]) | ||
| SelectField(choices=lambda: [("", "", {})]) | ||
| SelectField(choices=lambda: [(True, "t", {})]) | ||
| SelectField(choices=lambda: [(True, "t"), (False, "f", {})]) | ||
| SelectField(choices=lambda: [("", "")]) # pyright: ignore[reportDeprecated] | ||
| SelectField(choices=lambda: [(1, "1")]) # pyright: ignore[reportDeprecated] | ||
| SelectField(choices=lambda: [("", "", {})]) # pyright: ignore[reportDeprecated] | ||
| SelectField(choices=lambda: [(True, "t", {})]) # pyright: ignore[reportDeprecated] | ||
| SelectField(choices=lambda: [(True, "t"), (False, "f", {})]) # pyright: ignore[reportDeprecated] | ||
|
|
||
| # dict of tuple of tuples | ||
| SelectField(choices=lambda: {"a": (("", ""),)}) | ||
| SelectField(choices=lambda: {"a": ((1, "1"),)}) | ||
| SelectField(choices=lambda: {"a": (("", "", {}),)}) | ||
| SelectField(choices=lambda: {"a": ((True, "t", {}),)}) | ||
| SelectField(choices=lambda: {"a": ((True, "t"), (False, "f", {}))}) | ||
| SelectField(choices=lambda: {"a": ((True, "", {}),), "b": ((False, "f"),)}) | ||
| SelectField(choices=lambda: {"a": (("", ""),)}) # pyright: ignore[reportDeprecated] | ||
| SelectField(choices=lambda: {"a": ((1, "1"),)}) # pyright: ignore[reportDeprecated] | ||
| SelectField(choices=lambda: {"a": (("", "", {}),)}) # pyright: ignore[reportDeprecated] | ||
| SelectField(choices=lambda: {"a": ((True, "t", {}),)}) # pyright: ignore[reportDeprecated] | ||
| SelectField(choices=lambda: {"a": ((True, "t"), (False, "f", {}))}) # pyright: ignore[reportDeprecated] | ||
| SelectField(choices=lambda: {"a": ((True, "", {}),), "b": ((False, "f"),)}) # pyright: ignore[reportDeprecated] | ||
|
|
||
| # dict of list of tuples | ||
| SelectField(choices=lambda: {"a": [("", "")]}) | ||
| SelectField(choices=lambda: {"a": [(1, "1")]}) | ||
| SelectField(choices=lambda: {"a": [("", "", {})]}) | ||
| SelectField(choices=lambda: {"a": [(True, "t", {})]}) | ||
| SelectField(choices=lambda: {"a": [(True, "t"), (False, "f", {})]}) | ||
| SelectField(choices=lambda: {"a": [(True, "", {})], "b": [(False, "f")]}) | ||
| SelectField(choices=lambda: {"a": [("", "")]}) # pyright: ignore[reportDeprecated] | ||
| SelectField(choices=lambda: {"a": [(1, "1")]}) # pyright: ignore[reportDeprecated] | ||
| SelectField(choices=lambda: {"a": [("", "", {})]}) # pyright: ignore[reportDeprecated] | ||
| SelectField(choices=lambda: {"a": [(True, "t", {})]}) # pyright: ignore[reportDeprecated] | ||
| SelectField(choices=lambda: {"a": [(True, "t"), (False, "f", {})]}) # pyright: ignore[reportDeprecated] | ||
| SelectField(choices=lambda: {"a": [(True, "", {})], "b": [(False, "f")]}) # pyright: ignore[reportDeprecated] |
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,3 +1,4 @@ | ||
| version = "~= 3.2.1" | ||
| version = "3.3.*" | ||
| upstream-repository = "https://github.com/pallets-eco/wtforms" | ||
| dependencies = ["MarkupSafe"] | ||
| requires-python = ">=3.11" |
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
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,5 @@ | ||
| from collections.abc import Callable | ||
| from inspect import Signature | ||
| from typing import Any | ||
|
|
||
| def get_signature(callable: Callable[..., Any]) -> Signature: ... |
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,46 @@ | ||
| from collections.abc import Callable, Iterator, Sequence | ||
| from dataclasses import dataclass | ||
| from enum import EnumMeta | ||
| from typing import Any, Protocol, TypeAlias, type_check_only | ||
| from typing_extensions import Self | ||
|
|
||
| from markupsafe import Markup | ||
| from wtforms.fields import Field | ||
|
|
||
| _RawDataListChoice: TypeAlias = str | tuple[str] | tuple[str, str | None] | tuple[str, str | None, dict[str, Any]] | ||
| _DataListChoices: TypeAlias = Sequence[DataListChoice | _RawDataListChoice] | dict[str, str] | ||
|
|
||
| @type_check_only | ||
| class _DataListWidget(Protocol): | ||
| # see the comment on `wtforms.widgets.core._RenderArg` for a thorough explanation of the kwargs | ||
| def __call__(self, datalist: DataList, /, *, field: Field | None = None, **kwargs: Any) -> Markup: ... | ||
|
|
||
| __all__ = ("DataList", "DataListChoice", "enum_datalist") | ||
|
|
||
| @dataclass | ||
| class DataListChoice: | ||
| value: str | ||
| label: str | None = ... | ||
| render_kw: dict[str, Any] = ... | ||
| def __post_init__(self) -> None: ... | ||
| def __iter__(self) -> Iterator[tuple[str, str, dict[str, Any]]]: ... | ||
| @classmethod | ||
| def from_input(cls, input: DataListChoice | _RawDataListChoice) -> Self: ... | ||
|
|
||
| def enum_datalist(enum_cls: EnumMeta, *, by: str = "value", label: str | None = None) -> DataList: ... | ||
|
|
||
| class DataList: | ||
| widget: _DataListWidget | ||
| render_kw: dict[str, Any] | ||
| id: str | None | ||
| def __init__( | ||
| self, | ||
| choices: _DataListChoices | Callable[[Any, Any], _DataListChoices] | Callable[[], _DataListChoices] | None = None, | ||
| *, | ||
| render_kw: dict[str, Any] | None = None, | ||
| widget: _DataListWidget | None = None, | ||
| ) -> None: ... | ||
| def iter_choices(self, field: Field | None = None) -> list[DataListChoice]: ... | ||
| # by default this invokes the bound `widget.__call__` with the given kwargs and bound `render_kw` | ||
| # see the comment on `wtforms.widgets.core._RenderArg` for a thorough explanation | ||
| def __call__(self, field: Field | None = None, **kwargs: Any) -> Markup: ... | ||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. See above. |
||
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
Oops, something went wrong.
Oops, something went wrong.
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.
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.
See above.