Skip to content
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

5.0: Update django.forms.boundfield and django.forms.utils #2118

Merged
merged 10 commits into from
May 3, 2024
7 changes: 5 additions & 2 deletions django-stubs/forms/boundfield.pyi
Original file line number Diff line number Diff line change
Expand Up @@ -4,15 +4,15 @@ from typing import Any, overload
from django.forms.fields import Field
from django.forms.forms import BaseForm
from django.forms.renderers import BaseRenderer
from django.forms.utils import ErrorList
from django.forms.utils import ErrorList, RenderableFieldMixin
from django.forms.widgets import Widget
from django.utils.functional import _StrOrPromise, cached_property
from django.utils.safestring import SafeString
from typing_extensions import TypeAlias

_AttrsT: TypeAlias = dict[str, str | bool]

class BoundField:
class BoundField(RenderableFieldMixin):
form: BaseForm
field: Field
name: str
Expand All @@ -21,6 +21,7 @@ class BoundField:
html_initial_id: str
label: _StrOrPromise
help_text: _StrOrPromise
renderer: BaseRenderer
def __init__(self, form: BaseForm, field: Field, name: str) -> None: ...
@cached_property
def subwidgets(self) -> list[BoundWidget]: ...
Expand All @@ -33,6 +34,8 @@ class BoundField:
def __getitem__(self, idx: slice) -> list[BoundWidget]: ...
@property
def errors(self) -> ErrorList: ...
@property
def template_name(self) -> str: ...
def as_widget(
self, widget: Widget | None = ..., attrs: _AttrsT | None = ..., only_initial: bool = ...
) -> SafeString: ...
Expand Down
11 changes: 9 additions & 2 deletions django-stubs/forms/utils.pyi
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,15 @@ class RenderableMixin:
context: dict[str, Any] | None = ...,
renderer: BaseRenderer | type[BaseRenderer] | None = ...,
) -> SafeString: ...
__str__ = render
JaeHyuckSa marked this conversation as resolved.
Show resolved Hide resolved
__html__ = render
# This is a lie, but this is how it is supposed to be used,
# in reallity it is `__str__ = __html__ = render`:
def __str__(self) -> SafeString: ...
def __html__(self) -> SafeString: ...

class RenderableFieldMixin(RenderableMixin):
def as_field_group(self) -> SafeString: ...
def as_hidden(self) -> SafeString: ...
def as_widget(self) -> SafeString: ...

class RenderableFormMixin(RenderableMixin):
def as_p(self) -> SafeString: ...
Expand Down
4 changes: 4 additions & 0 deletions scripts/stubtest/allowlist.txt
Original file line number Diff line number Diff line change
Expand Up @@ -402,3 +402,7 @@ django.contrib.auth.models.AbstractUser.Meta
django.contrib.auth.models.PermissionsMixin.Meta
django.contrib.flatpages.forms.FlatpageForm.Meta
django.contrib.sessions.base_session.AbstractBaseSession.Meta

# Custom __str__ that we don't want to overcomplicate:
django.forms.utils.RenderableMixin.__str__
django.forms.utils.RenderableMixin.__html__
7 changes: 0 additions & 7 deletions scripts/stubtest/allowlist_todo_django50.txt
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,6 @@ django.contrib.gis.db.models.Prefetch.get_current_querysets
django.contrib.gis.db.models.Q.identity
django.contrib.gis.db.models.When.allowed_default
django.contrib.gis.forms.BaseForm._html_output
django.contrib.gis.forms.BoundField.get_context
django.contrib.gis.forms.BoundField.template_name
django.contrib.gis.forms.ClearableFileInput.checked
django.contrib.gis.forms.fields_for_model
django.contrib.gis.geos.prototypes.io.DEFAULT_TRIM_VALUE
Expand Down Expand Up @@ -93,16 +91,11 @@ django.db.models.sql.query.Query.join
django.db.models.sql.query.Query.resolve_lookup_value
django.db.models.sql.query.Query.setup_joins
django.forms.BaseForm._html_output
django.forms.BoundField.get_context
django.forms.BoundField.template_name
django.forms.ClearableFileInput.checked
django.forms.boundfield.BoundField.get_context
django.forms.boundfield.BoundField.template_name
django.forms.fields_for_model
django.forms.forms.BaseForm._html_output
django.forms.models.fields_for_model
django.forms.renderers.BaseRenderer.field_template_name
django.forms.renderers.Jinja2DivFormRenderer.__init__
django.forms.utils.RenderableFieldMixin
django.forms.widgets.ClearableFileInput.checked
django.template.autoreload
Loading