Skip to content

Commit

Permalink
5.0: Update django.forms.boundfield and django.forms.utils (#2118)
Browse files Browse the repository at this point in the history
Co-authored-by: Nikita Sobolev <[email protected]>
Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>
  • Loading branch information
3 people authored May 3, 2024
1 parent 4a7619f commit 856e8c2
Show file tree
Hide file tree
Showing 4 changed files with 18 additions and 11 deletions.
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
__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

0 comments on commit 856e8c2

Please sign in to comment.