From b019d7065e697906d50f7ab64fd1a8db95c103b3 Mon Sep 17 00:00:00 2001 From: SaJH Date: Sat, 4 May 2024 01:34:14 +0900 Subject: [PATCH 01/10] 5.0: Update django.forms.boundfield --- django-stubs/forms/boundfield.pyi | 5 ++++- scripts/stubtest/allowlist_todo_django50.txt | 6 ------ 2 files changed, 4 insertions(+), 7 deletions(-) diff --git a/django-stubs/forms/boundfield.pyi b/django-stubs/forms/boundfield.pyi index e3842b9da..2d7ded6fa 100644 --- a/django-stubs/forms/boundfield.pyi +++ b/django-stubs/forms/boundfield.pyi @@ -8,7 +8,7 @@ from django.forms.utils import ErrorList 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 +from typing_extensions import Self, TypeAlias _AttrsT: TypeAlias = dict[str, str | bool] @@ -33,6 +33,9 @@ class BoundField: def __getitem__(self, idx: slice) -> list[BoundWidget]: ... @property def errors(self) -> ErrorList: ... + @property + def template_name(self) -> str: ... + def get_context(self) -> dict[str, type[Self]]: ... def as_widget( self, widget: Widget | None = ..., attrs: _AttrsT | None = ..., only_initial: bool = ... ) -> SafeString: ... diff --git a/scripts/stubtest/allowlist_todo_django50.txt b/scripts/stubtest/allowlist_todo_django50.txt index de4288373..d382e6021 100644 --- a/scripts/stubtest/allowlist_todo_django50.txt +++ b/scripts/stubtest/allowlist_todo_django50.txt @@ -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 @@ -93,11 +91,7 @@ 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 From a341920d96e64261f2d92f0517d225fd4fe4ad36 Mon Sep 17 00:00:00 2001 From: SaJH Date: Sat, 4 May 2024 01:54:48 +0900 Subject: [PATCH 02/10] 5.0: Update django.forms.boundfield.BoundField.renderer --- django-stubs/forms/boundfield.pyi | 1 + 1 file changed, 1 insertion(+) diff --git a/django-stubs/forms/boundfield.pyi b/django-stubs/forms/boundfield.pyi index 2d7ded6fa..f3374b87f 100644 --- a/django-stubs/forms/boundfield.pyi +++ b/django-stubs/forms/boundfield.pyi @@ -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]: ... From 3ae50127b99292efc4336479b5ed29ed3060e55d Mon Sep 17 00:00:00 2001 From: SaJH Date: Sat, 4 May 2024 03:56:17 +0900 Subject: [PATCH 03/10] 5.0: Update django.forms.utils --- django-stubs/forms/boundfield.pyi | 8 ++++---- django-stubs/forms/utils.pyi | 14 +++++++++++--- scripts/django_tests_settings.py | 4 ++++ scripts/stubtest/allowlist_todo_django50.txt | 1 - 4 files changed, 19 insertions(+), 8 deletions(-) diff --git a/django-stubs/forms/boundfield.pyi b/django-stubs/forms/boundfield.pyi index f3374b87f..b01601bd4 100644 --- a/django-stubs/forms/boundfield.pyi +++ b/django-stubs/forms/boundfield.pyi @@ -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 Self, TypeAlias +from typing_extensions import TypeAlias _AttrsT: TypeAlias = dict[str, str | bool] -class BoundField: +class BoundField(RenderableFieldMixin): form: BaseForm field: Field name: str @@ -36,7 +36,7 @@ class BoundField: def errors(self) -> ErrorList: ... @property def template_name(self) -> str: ... - def get_context(self) -> dict[str, type[Self]]: ... + def get_context(self) -> dict[str, Any]: ... def as_widget( self, widget: Widget | None = ..., attrs: _AttrsT | None = ..., only_initial: bool = ... ) -> SafeString: ... diff --git a/django-stubs/forms/utils.pyi b/django-stubs/forms/utils.pyi index 6533e7b0c..44f3e79fe 100644 --- a/django-stubs/forms/utils.pyi +++ b/django-stubs/forms/utils.pyi @@ -1,7 +1,7 @@ from collections import UserList from collections.abc import Mapping, Sequence from datetime import datetime -from typing import Any +from typing import Any, Callable from django.core.exceptions import ValidationError from django.core.files.uploadedfile import UploadedFile @@ -26,8 +26,16 @@ class RenderableMixin: context: dict[str, Any] | None = ..., renderer: BaseRenderer | type[BaseRenderer] | None = ..., ) -> SafeString: ... - __str__ = render - __html__ = render + + __str__: Callable[..., SafeString] = ... + __html__: Callable[..., SafeString] = ... + +class RenderableFieldMixin(RenderableMixin): + def as_field_group(self) -> SafeString: ... + def as_hidden(self) -> SafeString: ... + def as_widget(self) -> SafeString: ... + __str__: Callable[..., SafeString] + __html__: Callable[..., SafeString] class RenderableFormMixin(RenderableMixin): def as_p(self) -> SafeString: ... diff --git a/scripts/django_tests_settings.py b/scripts/django_tests_settings.py index b005ec50a..f20a2e36a 100644 --- a/scripts/django_tests_settings.py +++ b/scripts/django_tests_settings.py @@ -11,3 +11,7 @@ ] STATIC_URL = "static/" + + +GDAL_LIBRARY_PATH = "/opt/homebrew/opt/gdal/lib/libgdal.dylib" +GEOS_LIBRARY_PATH = "/opt/homebrew/opt/geos/lib/libgeos_c.dylib" diff --git a/scripts/stubtest/allowlist_todo_django50.txt b/scripts/stubtest/allowlist_todo_django50.txt index d382e6021..0cb18fa3d 100644 --- a/scripts/stubtest/allowlist_todo_django50.txt +++ b/scripts/stubtest/allowlist_todo_django50.txt @@ -97,6 +97,5 @@ 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 From a86ad96789c6d0fffa875aea07824f24e53e8d71 Mon Sep 17 00:00:00 2001 From: Jae Hyuck Sa Date: Sat, 4 May 2024 04:09:23 +0900 Subject: [PATCH 04/10] Update django_tests_settings.py --- scripts/django_tests_settings.py | 4 ---- 1 file changed, 4 deletions(-) diff --git a/scripts/django_tests_settings.py b/scripts/django_tests_settings.py index f20a2e36a..b005ec50a 100644 --- a/scripts/django_tests_settings.py +++ b/scripts/django_tests_settings.py @@ -11,7 +11,3 @@ ] STATIC_URL = "static/" - - -GDAL_LIBRARY_PATH = "/opt/homebrew/opt/gdal/lib/libgdal.dylib" -GEOS_LIBRARY_PATH = "/opt/homebrew/opt/geos/lib/libgeos_c.dylib" From 3db9752b6ea9584f5fd7f69180a37717842880ad Mon Sep 17 00:00:00 2001 From: Jae Hyuck Sa Date: Sat, 4 May 2024 04:21:42 +0900 Subject: [PATCH 05/10] Update django-stubs/forms/boundfield.pyi Co-authored-by: Nikita Sobolev --- django-stubs/forms/boundfield.pyi | 1 - 1 file changed, 1 deletion(-) diff --git a/django-stubs/forms/boundfield.pyi b/django-stubs/forms/boundfield.pyi index b01601bd4..e24c29fd8 100644 --- a/django-stubs/forms/boundfield.pyi +++ b/django-stubs/forms/boundfield.pyi @@ -36,7 +36,6 @@ class BoundField(RenderableFieldMixin): def errors(self) -> ErrorList: ... @property def template_name(self) -> str: ... - def get_context(self) -> dict[str, Any]: ... def as_widget( self, widget: Widget | None = ..., attrs: _AttrsT | None = ..., only_initial: bool = ... ) -> SafeString: ... From 976fea9a2f0c9ca7d08a144763720b53230f4f0d Mon Sep 17 00:00:00 2001 From: Nikita Sobolev Date: Fri, 3 May 2024 22:36:06 +0300 Subject: [PATCH 06/10] Let's try this --- django-stubs/forms/utils.pyi | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) diff --git a/django-stubs/forms/utils.pyi b/django-stubs/forms/utils.pyi index 44f3e79fe..fdf2df03a 100644 --- a/django-stubs/forms/utils.pyi +++ b/django-stubs/forms/utils.pyi @@ -26,16 +26,15 @@ class RenderableMixin: context: dict[str, Any] | None = ..., renderer: BaseRenderer | type[BaseRenderer] | None = ..., ) -> SafeString: ... - - __str__: Callable[..., SafeString] = ... - __html__: Callable[..., SafeString] = ... + __str__ = render + __html__ = render class RenderableFieldMixin(RenderableMixin): def as_field_group(self) -> SafeString: ... def as_hidden(self) -> SafeString: ... def as_widget(self) -> SafeString: ... - __str__: Callable[..., SafeString] - __html__: Callable[..., SafeString] + def __str__(self) -> str: ... + __html__ = __str__ # type: ignore[override] class RenderableFormMixin(RenderableMixin): def as_p(self) -> SafeString: ... From 002ab85b6344c0f25c4c1fbb8081fafcaa6394ee Mon Sep 17 00:00:00 2001 From: "pre-commit-ci[bot]" <66853113+pre-commit-ci[bot]@users.noreply.github.com> Date: Fri, 3 May 2024 19:37:20 +0000 Subject: [PATCH 07/10] [pre-commit.ci] auto fixes from pre-commit.com hooks --- django-stubs/forms/utils.pyi | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/django-stubs/forms/utils.pyi b/django-stubs/forms/utils.pyi index fdf2df03a..9b55bc0aa 100644 --- a/django-stubs/forms/utils.pyi +++ b/django-stubs/forms/utils.pyi @@ -1,7 +1,7 @@ from collections import UserList from collections.abc import Mapping, Sequence from datetime import datetime -from typing import Any, Callable +from typing import Any from django.core.exceptions import ValidationError from django.core.files.uploadedfile import UploadedFile @@ -33,7 +33,6 @@ class RenderableFieldMixin(RenderableMixin): def as_field_group(self) -> SafeString: ... def as_hidden(self) -> SafeString: ... def as_widget(self) -> SafeString: ... - def __str__(self) -> str: ... __html__ = __str__ # type: ignore[override] class RenderableFormMixin(RenderableMixin): From 66f3c55409c7d26d166228922052283b1d327199 Mon Sep 17 00:00:00 2001 From: Nikita Sobolev Date: Fri, 3 May 2024 22:39:28 +0300 Subject: [PATCH 08/10] Update utils.pyi --- django-stubs/forms/utils.pyi | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/django-stubs/forms/utils.pyi b/django-stubs/forms/utils.pyi index 9b55bc0aa..a738a167b 100644 --- a/django-stubs/forms/utils.pyi +++ b/django-stubs/forms/utils.pyi @@ -26,14 +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: ... + __html__ = __str__ class RenderableFieldMixin(RenderableMixin): def as_field_group(self) -> SafeString: ... def as_hidden(self) -> SafeString: ... def as_widget(self) -> SafeString: ... - __html__ = __str__ # type: ignore[override] class RenderableFormMixin(RenderableMixin): def as_p(self) -> SafeString: ... From 91b1c6a43b1b7d2da817fcb3e5268d7e377c460d Mon Sep 17 00:00:00 2001 From: Nikita Sobolev Date: Fri, 3 May 2024 22:41:51 +0300 Subject: [PATCH 09/10] Update utils.pyi --- django-stubs/forms/utils.pyi | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/django-stubs/forms/utils.pyi b/django-stubs/forms/utils.pyi index a738a167b..a2a5c4653 100644 --- a/django-stubs/forms/utils.pyi +++ b/django-stubs/forms/utils.pyi @@ -29,7 +29,7 @@ class RenderableMixin: # 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: ... - __html__ = __str__ + def __html__(self) -> SafeString: ... class RenderableFieldMixin(RenderableMixin): def as_field_group(self) -> SafeString: ... From ee0e1ea45ac44d7aa8d80d867f0a45c64685a146 Mon Sep 17 00:00:00 2001 From: Nikita Sobolev Date: Fri, 3 May 2024 22:44:22 +0300 Subject: [PATCH 10/10] Update allowlist.txt --- scripts/stubtest/allowlist.txt | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/scripts/stubtest/allowlist.txt b/scripts/stubtest/allowlist.txt index ff300149e..34b39e6a4 100644 --- a/scripts/stubtest/allowlist.txt +++ b/scripts/stubtest/allowlist.txt @@ -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__