Bump WTForms to 3.1.* (#10868)

Co-authored-by: sobolevn <mail@sobolevn.me>
This commit is contained in:
David Salvisberg
2023-10-12 04:31:22 +02:00
committed by GitHub
parent 7e2a3413fa
commit 95cee3100a
6 changed files with 103 additions and 6 deletions

View File

@@ -0,0 +1,67 @@
from __future__ import annotations
from wtforms import SelectField
# 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", {})))
# list of tuples
SelectField(choices=[("", "")])
SelectField(choices=[(1, "1")])
SelectField(choices=[("", "", {})])
SelectField(choices=[(True, "t", {})])
SelectField(choices=[(True, "t"), (False, "f", {})])
# 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"),)})
# 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")]})
# 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", {})))
# 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", {})])
# 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"),)})
# 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")]})

View File

@@ -1,3 +1,3 @@
version = "3.0.*"
version = "3.1.*"
upstream_repository = "https://github.com/wtforms/wtforms"
requires = ["MarkupSafe"]

View File

@@ -7,9 +7,10 @@ from wtforms.form import BaseForm
from wtforms.meta import DefaultMeta, _SupportsGettextAndNgettext
# technically this allows a list, but we're more strict for type safety
_Choice: TypeAlias = tuple[Any, str]
_GroupedChoices: TypeAlias = dict[str, Iterable[_Choice]]
_FullChoice: TypeAlias = tuple[Any, str, bool] # value, label, selected
_Choice: TypeAlias = tuple[Any, str] | tuple[Any, str, dict[str, Any]]
# it's too difficult to get type safety here due to to nested partially invariant collections
_GroupedChoices: TypeAlias = dict[str, Any] # Any should be Collection[_Choice]
_FullChoice: TypeAlias = tuple[Any, str, bool, dict[str, Any]] # value, label, selected, render_kw
_FullGroupedChoices: TypeAlias = tuple[str, Iterable[_FullChoice]]
_Option: TypeAlias = SelectFieldBase._Option
@@ -50,7 +51,7 @@ class SelectField(SelectFieldBase):
label: str | None = None,
validators: tuple[_Validator[_FormT, Self], ...] | list[Any] | None = None,
coerce: Callable[[Any], Any] = ...,
choices: Iterable[_Choice] | _GroupedChoices | None = None,
choices: Iterable[_Choice] | _GroupedChoices | Callable[[], Iterable[_Choice] | _GroupedChoices] | None = None,
validate_choice: bool = True,
*,
filters: Sequence[_Filter] = (),

View File

@@ -95,6 +95,26 @@ class MonthField(DateField):
_meta: DefaultMeta | None = None,
) -> None: ...
class WeekField(DateField):
def __init__(
self,
label: str | None = None,
validators: tuple[_Validator[_FormT, Self], ...] | list[Any] | None = None,
format: str | list[str] = "%Y-W%W", # only difference is the default value
*,
filters: Sequence[_Filter] = (),
description: str = "",
id: str | None = None,
default: time | Callable[[], time] | None = None,
widget: _Widget[Self] | None = None,
render_kw: dict[str, Any] | None = None,
name: str | None = None,
_form: BaseForm | None = None,
_prefix: str = "",
_translations: _SupportsGettextAndNgettext | None = None,
_meta: DefaultMeta | None = None,
) -> None: ...
class DateTimeLocalField(DateTimeField):
def __init__(
self,

View File

@@ -62,3 +62,4 @@ class SearchField(StringField): ...
class TelField(StringField): ...
class URLField(StringField): ...
class EmailField(StringField): ...
class ColorField(StringField): ...

View File

@@ -99,7 +99,7 @@ class MacAddress(Regexp):
class URL(Regexp):
validate_hostname: HostnameValidation
def __init__(self, require_tld: bool = True, message: str | None = None) -> None: ...
def __init__(self, require_tld: bool = True, allow_ip: bool = True, message: str | None = None) -> None: ...
def __call__(self, form: BaseForm, field: StringField) -> None: ... # type: ignore[override]
class UUID:
@@ -143,6 +143,12 @@ class HostnameValidation:
def __init__(self, require_tld: bool = True, allow_ip: bool = False) -> None: ...
def __call__(self, hostname: str) -> bool: ...
class ReadOnly:
def __call__(self, form: BaseForm, field: Field) -> None: ...
class Disabled:
def __call__(self, form: BaseForm, field: Field) -> None: ...
email = Email
equal_to = EqualTo
ip_address = IPAddress
@@ -156,3 +162,5 @@ regexp = Regexp
url = URL
any_of = AnyOf
none_of = NoneOf
readonly = ReadOnly
disabled = Disabled