8000 Add stubs for WTForms by Daverball · Pull Request #10557 · python/typeshed · GitHub
[go: up one dir, main page]

Skip to content

Add stubs for WTForms #10557

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 11 commits into from
Sep 29, 2023
Merged
Prev Previous commit
Next Next commit
Fixes pytype crash
  • Loading branch information
Daverball committed Aug 10, 2023
commit fba94a629d90c9e87a19593302a2c7c72765eeeb
17 changes: 10 additions & 7 deletions stubs/WTForms/wtforms/fields/choices.pyi
Original file line number Diff line number Diff line change
Expand Up @@ -12,12 +12,18 @@ _GroupedChoices: TypeAlias = dict[str, Iterable[_Choice]]
_FullChoice: TypeAlias = tuple[Any, str, bool] # value, label, selected
_FullGroupedChoices: TypeAlias = tuple[str, Iterable[_FullChoice]]

# this is defined anonymously inside SelectFieldBase, we have to pull it
# out of there so pytype doesn't crash
class _Option(Field):
checked: bool

class SelectFieldBase(Field):
option_widget: _Widget[_Option]
def __init__(
self,
label: str | None = None,
validators: tuple[_Validator[_FormT, Self], ...] | list[Any] | None = None,
option_widget: _Widget[SelectFieldBase._Option] | None = None,
option_widget: _Widget[_Option] | None = None,
*,
filters: Sequence[_Filter] = (),
description: str = "",
Expand All @@ -34,11 +40,8 @@ class SelectFieldBase(Field):
def iter_choices(self) -> Iterator[_FullChoice]: ...
def has_groups(self) -> bool: ...
def iter_groups(self) -> Iterator[_FullGroupedChoices]: ...
def __iter__(self) -> Iterator[SelectFieldBase._Option]: ...

class _Option(Field):
checked: bool
option_widget: _Widget[_Option]
def __iter__(self) -> Iterator[_Option]: ...
_Option: type[_Option]

class SelectField(SelectFieldBase):
coerce: Callable[[Any], Any]
Expand All @@ -57,7 +60,7 @@ class SelectField(SelectFieldBase):
id: str | None = None,
default: object | None = None,
widget: _Widget[Self] | None = None,
option_widget: _Widget[SelectFieldBase._Option] | None = None,
option_widget: _Widget[_Option] | None = None,
render_kw: dict[str, Any] | None = None,
name: str | None = None,
_form: BaseForm | None = None,
Expand Down
3 changes: 2 additions & 1 deletion stubs/WTForms/wtforms/widgets/core.pyi
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ from typing_extensions import Literal

from markupsafe import Markup
from wtforms.fields import Field, FormField, SelectFieldBase, StringField
from wtforms.fields.choices import _Option

__all__ = (
"CheckboxInput",
Expand Down Expand Up @@ -88,7 +89,7 @@ class Select:
def render_option(cls, value: object, label: str, selected: bool, **kwargs: object) -> Markup: ...

class Option:
def __call__(self, field: SelectFieldBase._Option, **kwargs: object) -> Markup: ...
def __call__(self, field: _Option, **kwargs: object) -> Markup: ...

class SearchInput(Input): ...
class TelInput(Input): ...
Expand Down
0