From 9b6c3b34ef085581985a8d4098c3600f035d08ab Mon Sep 17 00:00:00 2001 From: Tony Narlock Date: Fri, 3 May 2024 17:02:37 -0500 Subject: [PATCH 1/5] BaseBackend.get_user: Relax `user_id` param type (#2121) In theory, this pk could be anything, given that `AUTH_USER_MODEL` can resolved to any custom model (often a `AbstractBaseUser` subclass.) See also: - https://docs.djangoproject.com/en/5.0/topics/auth/customizing/#substituting-a-custom-user-model - https://github.com/django/django/blob/5.0.4/django/contrib/auth/backends.py --- django-stubs/contrib/auth/backends.pyi | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/django-stubs/contrib/auth/backends.pyi b/django-stubs/contrib/auth/backends.pyi index d4f3aeb67..87d0bf825 100644 --- a/django-stubs/contrib/auth/backends.pyi +++ b/django-stubs/contrib/auth/backends.pyi @@ -13,7 +13,7 @@ UserModel: Any class BaseBackend: def authenticate(self, request: HttpRequest | None, **kwargs: Any) -> AbstractBaseUser | None: ... - def get_user(self, user_id: int) -> AbstractBaseUser | None: ... + def get_user(self, user_id: Any) -> AbstractBaseUser | None: ... def get_user_permissions(self, user_obj: _AnyUser, obj: Model | None = ...) -> set[str]: ... def get_group_permissions(self, user_obj: _AnyUser, obj: Model | None = ...) -> set[str]: ... def get_all_permissions(self, user_obj: _AnyUser, obj: Model | None = ...) -> set[str]: ... From c3a7e54d0066a16b3ab3bee09e77bb461bfff2f8 Mon Sep 17 00:00:00 2001 From: Jae Hyuck Sa Date: Sat, 4 May 2024 07:04:46 +0900 Subject: [PATCH 2/5] 5.0: Update `django.forms.renderers` (#2119) * 5.0: Update django.forms.renderers * Update allowlist.txt --- django-stubs/forms/renderers.pyi | 1 + scripts/stubtest/allowlist.txt | 1 + scripts/stubtest/allowlist_todo_django50.txt | 2 -- 3 files changed, 2 insertions(+), 2 deletions(-) diff --git a/django-stubs/forms/renderers.pyi b/django-stubs/forms/renderers.pyi index b3f642af5..859a35a16 100644 --- a/django-stubs/forms/renderers.pyi +++ b/django-stubs/forms/renderers.pyi @@ -12,6 +12,7 @@ def get_default_renderer() -> BaseRenderer: ... class BaseRenderer: form_template_name: str formset_template_name: str + field_template_name: str def get_template(self, template_name: str) -> Any: ... def render(self, template_name: str, context: dict[str, Any], request: HttpRequest | None = ...) -> str: ... diff --git a/scripts/stubtest/allowlist.txt b/scripts/stubtest/allowlist.txt index 34b39e6a4..44113453d 100644 --- a/scripts/stubtest/allowlist.txt +++ b/scripts/stubtest/allowlist.txt @@ -370,6 +370,7 @@ django.forms.formsets.BaseFormSet.forms django.forms.formsets.BaseFormSet.management_form django.forms.renderers.EngineMixin.engine django.forms.renderers.Jinja2.backend +django.forms.renderers.Jinja2DivFormRenderer.__init__ django.http.HttpRequest.accepted_types django.http.HttpRequest.headers django.http.request.HttpRequest.accepted_types diff --git a/scripts/stubtest/allowlist_todo_django50.txt b/scripts/stubtest/allowlist_todo_django50.txt index 0cb18fa3d..0c2eea9a6 100644 --- a/scripts/stubtest/allowlist_todo_django50.txt +++ b/scripts/stubtest/allowlist_todo_django50.txt @@ -95,7 +95,5 @@ django.forms.ClearableFileInput.checked 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.widgets.ClearableFileInput.checked django.template.autoreload From 2d8b5d21f8374c096ab1f73833eeda9df894b9ba Mon Sep 17 00:00:00 2001 From: Jae Hyuck Sa Date: Sun, 5 May 2024 01:23:00 +0900 Subject: [PATCH 3/5] 5.0: Update django.forms.forms (#2122) --- django-stubs/forms/forms.pyi | 9 --------- scripts/stubtest/allowlist_todo_django50.txt | 3 --- 2 files changed, 12 deletions(-) diff --git a/django-stubs/forms/forms.pyi b/django-stubs/forms/forms.pyi index fbf8f5008..46d9eb199 100644 --- a/django-stubs/forms/forms.pyi +++ b/django-stubs/forms/forms.pyi @@ -8,7 +8,6 @@ from django.forms.renderers import BaseRenderer from django.forms.utils import ErrorDict, ErrorList, RenderableFormMixin, _DataT, _FilesT from django.forms.widgets import Media, MediaDefiningClass from django.utils.functional import _StrOrPromise, cached_property -from django.utils.safestring import SafeString class DeclarativeFieldsMetaclass(MediaDefiningClass): ... @@ -71,14 +70,6 @@ class BaseForm(RenderableFormMixin): def hidden_fields(self) -> list[BoundField]: ... def visible_fields(self) -> list[BoundField]: ... def get_initial_for_field(self, field: Field, field_name: str) -> Any: ... - def _html_output( - self, - normal_row: str, - error_row: str, - row_ender: str, - help_text_html: str, - errors_on_separate_row: bool, - ) -> SafeString: ... class Form(BaseForm, metaclass=DeclarativeFieldsMetaclass): base_fields: ClassVar[dict[str, Field]] diff --git a/scripts/stubtest/allowlist_todo_django50.txt b/scripts/stubtest/allowlist_todo_django50.txt index 0c2eea9a6..418198c40 100644 --- a/scripts/stubtest/allowlist_todo_django50.txt +++ b/scripts/stubtest/allowlist_todo_django50.txt @@ -22,7 +22,6 @@ django.contrib.gis.db.models.Lookup.allowed_default 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.ClearableFileInput.checked django.contrib.gis.forms.fields_for_model django.contrib.gis.geos.prototypes.io.DEFAULT_TRIM_VALUE @@ -90,10 +89,8 @@ django.db.models.sql.query.Query.build_filtered_relation_q 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.ClearableFileInput.checked django.forms.fields_for_model -django.forms.forms.BaseForm._html_output django.forms.models.fields_for_model django.forms.widgets.ClearableFileInput.checked django.template.autoreload From 17401ca6ec17275e0cd673c81387ea86743b1e17 Mon Sep 17 00:00:00 2001 From: Jae Hyuck Sa Date: Sun, 5 May 2024 02:31:02 +0900 Subject: [PATCH 4/5] 5.0: Update django.contrib.gis.db.backends.sqatialite.schema (#2123) --- django-stubs/contrib/gis/db/backends/spatialite/schema.pyi | 5 ++++- scripts/stubtest/allowlist_todo_django50.txt | 1 - 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/django-stubs/contrib/gis/db/backends/spatialite/schema.pyi b/django-stubs/contrib/gis/db/backends/spatialite/schema.pyi index 934da3f57..eb85638f8 100644 --- a/django-stubs/contrib/gis/db/backends/spatialite/schema.pyi +++ b/django-stubs/contrib/gis/db/backends/spatialite/schema.pyi @@ -21,5 +21,8 @@ class SpatialiteSchemaEditor(DatabaseSchemaEditor): def add_field(self, model: Any, field: Any) -> None: ... def remove_field(self, model: Any, field: Any) -> None: ... def alter_db_table( - self, model: Any, old_db_table: Any, new_db_table: Any, disable_constraints: bool = ... + self, + model: Any, + old_db_table: Any, + new_db_table: Any, ) -> None: ... diff --git a/scripts/stubtest/allowlist_todo_django50.txt b/scripts/stubtest/allowlist_todo_django50.txt index 418198c40..2818f0ace 100644 --- a/scripts/stubtest/allowlist_todo_django50.txt +++ b/scripts/stubtest/allowlist_todo_django50.txt @@ -5,7 +5,6 @@ django.contrib.contenttypes.fields.GenericForeignKey.get_content_type django.contrib.contenttypes.fields.GenericForeignKey.get_prefetch_querysets django.contrib.contenttypes.prefetch -django.contrib.gis.db.backends.spatialite.schema.SpatialiteSchemaEditor.alter_db_table django.contrib.gis.db.models.Case.allowed_default django.contrib.gis.db.models.ExpressionWrapper.allowed_default django.contrib.gis.db.models.F.allowed_default From b0858a799b2cc7e9abec1e05ec5c0ce2c1875320 Mon Sep 17 00:00:00 2001 From: Jae Hyuck Sa Date: Sun, 5 May 2024 16:39:02 +0900 Subject: [PATCH 5/5] Fix Any value for schemea (#2124) --- .../contrib/gis/db/backends/mysql/schema.pyi | 14 +++++++----- .../contrib/gis/db/backends/oracle/schema.pyi | 14 +++++++----- .../gis/db/backends/spatialite/schema.pyi | 22 +++++++++++-------- django-stubs/db/backends/base/schema.pyi | 12 +++++----- django-stubs/db/backends/mysql/schema.pyi | 6 +++-- django-stubs/db/backends/oracle/schema.pyi | 8 ++++--- .../db/backends/postgresql/schema.pyi | 6 +++-- 7 files changed, 50 insertions(+), 32 deletions(-) diff --git a/django-stubs/contrib/gis/db/backends/mysql/schema.pyi b/django-stubs/contrib/gis/db/backends/mysql/schema.pyi index a2b977006..c93f1286a 100644 --- a/django-stubs/contrib/gis/db/backends/mysql/schema.pyi +++ b/django-stubs/contrib/gis/db/backends/mysql/schema.pyi @@ -2,6 +2,8 @@ from logging import Logger from typing import Any from django.db.backends.mysql.schema import DatabaseSchemaEditor +from django.db.models.base import Model +from django.db.models.fields import Field logger: Logger @@ -10,9 +12,11 @@ class MySQLGISSchemaEditor(DatabaseSchemaEditor): sql_drop_spatial_index: str geometry_sql: Any def __init__(self, *args: Any, **kwargs: Any) -> None: ... - def skip_default(self, field: Any) -> Any: ... - def column_sql(self, model: Any, field: Any, include_default: bool = ...) -> Any: ... - def create_model(self, model: Any) -> None: ... - def add_field(self, model: Any, field: Any) -> None: ... - def remove_field(self, model: Any, field: Any) -> None: ... + def skip_default(self, field: Field) -> bool: ... + def column_sql( + self, model: type[Model], field: Field, include_default: bool = ... + ) -> tuple[None, None] | tuple[str, list[Any]]: ... + def create_model(self, model: type[Model]) -> None: ... + def add_field(self, model: type[Model], field: Field) -> None: ... + def remove_field(self, model: type[Model], field: Field) -> None: ... def create_spatial_indexes(self) -> None: ... diff --git a/django-stubs/contrib/gis/db/backends/oracle/schema.pyi b/django-stubs/contrib/gis/db/backends/oracle/schema.pyi index 7e5ffdb27..76a89677f 100644 --- a/django-stubs/contrib/gis/db/backends/oracle/schema.pyi +++ b/django-stubs/contrib/gis/db/backends/oracle/schema.pyi @@ -1,6 +1,8 @@ from typing import Any from django.db.backends.oracle.schema import DatabaseSchemaEditor +from django.db.models.base import Model +from django.db.models.fields import Field class OracleGISSchemaEditor(DatabaseSchemaEditor): sql_add_geometry_metadata: str @@ -11,9 +13,11 @@ class OracleGISSchemaEditor(DatabaseSchemaEditor): geometry_sql: Any def __init__(self, *args: Any, **kwargs: Any) -> None: ... def geo_quote_name(self, name: Any) -> Any: ... - def column_sql(self, model: Any, field: Any, include_default: bool = ...) -> Any: ... - def create_model(self, model: Any) -> None: ... - def delete_model(self, model: Any) -> None: ... - def add_field(self, model: Any, field: Any) -> None: ... - def remove_field(self, model: Any, field: Any) -> None: ... + def column_sql( + self, model: type[Model], field: Field, include_default: bool = ... + ) -> tuple[None, None] | tuple[str, list[Any]]: ... + def create_model(self, model: type[Model]) -> None: ... + def delete_model(self, model: type[Model]) -> None: ... + def add_field(self, model: type[Model], field: Field) -> None: ... + def remove_field(self, model: type[Model], field: Field) -> None: ... def run_geometry_sql(self) -> None: ... diff --git a/django-stubs/contrib/gis/db/backends/spatialite/schema.pyi b/django-stubs/contrib/gis/db/backends/spatialite/schema.pyi index eb85638f8..b655ac23e 100644 --- a/django-stubs/contrib/gis/db/backends/spatialite/schema.pyi +++ b/django-stubs/contrib/gis/db/backends/spatialite/schema.pyi @@ -1,6 +1,8 @@ from typing import Any from django.db.backends.sqlite3.schema import DatabaseSchemaEditor +from django.db.models.base import Model +from django.db.models.fields import Field class SpatialiteSchemaEditor(DatabaseSchemaEditor): sql_add_geometry_column: str @@ -14,15 +16,17 @@ class SpatialiteSchemaEditor(DatabaseSchemaEditor): geometry_sql: Any def __init__(self, *args: Any, **kwargs: Any) -> None: ... def geo_quote_name(self, name: Any) -> Any: ... - def column_sql(self, model: Any, field: Any, include_default: bool = ...) -> Any: ... - def remove_geometry_metadata(self, model: Any, field: Any) -> None: ... - def create_model(self, model: Any) -> None: ... - def delete_model(self, model: Any, **kwargs: Any) -> None: ... - def add_field(self, model: Any, field: Any) -> None: ... - def remove_field(self, model: Any, field: Any) -> None: ... + def column_sql( + self, model: type[Model], field: Field, include_default: bool = ... + ) -> tuple[None, None] | tuple[str, list[Any]]: ... + def remove_geometry_metadata(self, model: type[Model], field: Field) -> None: ... + def create_model(self, model: type[Model]) -> None: ... + def delete_model(self, model: type[Model], **kwargs: Any) -> None: ... + def add_field(self, model: type[Model], field: Field) -> None: ... + def remove_field(self, model: type[Model], field: Field) -> None: ... def alter_db_table( self, - model: Any, - old_db_table: Any, - new_db_table: Any, + model: type[Model], + old_db_table: str, + new_db_table: str, ) -> None: ... diff --git a/django-stubs/db/backends/base/schema.pyi b/django-stubs/db/backends/base/schema.pyi index 8abf68484..c9db75875 100644 --- a/django-stubs/db/backends/base/schema.pyi +++ b/django-stubs/db/backends/base/schema.pyi @@ -74,8 +74,8 @@ class BaseDatabaseSchemaEditor(AbstractContextManager[Any]): def column_sql( self, model: type[Model], field: Field, include_default: bool = ... ) -> tuple[None, None] | tuple[str, list[Any]]: ... - def skip_default(self, field: Any) -> bool: ... - def skip_default_on_alter(self, field: Any) -> bool: ... + def skip_default(self, field: Field) -> bool: ... + def skip_default_on_alter(self, field: Field) -> bool: ... def prepare_default(self, value: Any) -> Any: ... def db_default_sql(self, field: Field) -> _AsSqlType: ... def effective_default(self, field: Field) -> int | str: ... @@ -101,10 +101,10 @@ class BaseDatabaseSchemaEditor(AbstractContextManager[Any]): ) -> None: ... def alter_db_table(self, model: type[Model], old_db_table: str, new_db_table: str) -> None: ... def alter_db_table_comment( - self, model: type[Model], old_db_table_comment: str | None, new_db_table_comment: str + self, model: type[Model], old_db_table_comment: str, new_db_table_comment: str ) -> None: ... - def alter_db_tablespace(self, model: Any, old_db_tablespace: Any, new_db_tablespace: Any) -> None: ... - def add_field(self, model: Any, field: Any) -> None: ... - def remove_field(self, model: Any, field: Any) -> None: ... + def alter_db_tablespace(self, model: type[Model], old_db_tablespace: str, new_db_tablespace: str) -> None: ... + def add_field(self, model: type[Model], field: Field) -> None: ... + def remove_field(self, model: type[Model], field: Field) -> None: ... def alter_field(self, model: type[Model], old_field: Field, new_field: Field, strict: bool = ...) -> None: ... def remove_procedure(self, procedure_name: Any, param_types: Any = ...) -> None: ... diff --git a/django-stubs/db/backends/mysql/schema.pyi b/django-stubs/db/backends/mysql/schema.pyi index e84b4b2de..4a274a1da 100644 --- a/django-stubs/db/backends/mysql/schema.pyi +++ b/django-stubs/db/backends/mysql/schema.pyi @@ -2,6 +2,8 @@ from typing import Any from django.db.backends.base.schema import BaseDatabaseSchemaEditor from django.db.backends.mysql.base import DatabaseWrapper +from django.db.models.base import Model +from django.db.models.fields import Field class DatabaseSchemaEditor(BaseDatabaseSchemaEditor): connection: DatabaseWrapper @@ -22,5 +24,5 @@ class DatabaseSchemaEditor(BaseDatabaseSchemaEditor): @property def sql_rename_column(self) -> str: ... # type: ignore[override] def quote_value(self, value: Any) -> str: ... - def skip_default(self, field: Any) -> bool: ... - def add_field(self, model: Any, field: Any) -> None: ... + def skip_default(self, field: Field) -> bool: ... + def add_field(self, model: type[Model], field: Field) -> None: ... diff --git a/django-stubs/db/backends/oracle/schema.pyi b/django-stubs/db/backends/oracle/schema.pyi index ed30a2bc5..885f65453 100644 --- a/django-stubs/db/backends/oracle/schema.pyi +++ b/django-stubs/db/backends/oracle/schema.pyi @@ -2,6 +2,8 @@ from typing import Any from django.db.backends.base.schema import BaseDatabaseSchemaEditor from django.db.backends.oracle.base import DatabaseWrapper +from django.db.models.base import Model +from django.db.models.fields import Field class DatabaseSchemaEditor(BaseDatabaseSchemaEditor): connection: DatabaseWrapper @@ -16,8 +18,8 @@ class DatabaseSchemaEditor(BaseDatabaseSchemaEditor): sql_delete_table: str sql_create_index: str def quote_value(self, value: Any) -> str: ... - def remove_field(self, model: Any, field: Any) -> None: ... - def delete_model(self, model: Any) -> None: ... - def alter_field(self, model: Any, old_field: Any, new_field: Any, strict: bool = ...) -> None: ... + def remove_field(self, model: type[Model], field: Field) -> None: ... + def delete_model(self, model: type[Model]) -> None: ... + def alter_field(self, model: type[Model], old_field: Field, new_field: Field, strict: bool = ...) -> None: ... def normalize_name(self, name: Any) -> str: ... def prepare_default(self, value: Any) -> Any: ... diff --git a/django-stubs/db/backends/postgresql/schema.pyi b/django-stubs/db/backends/postgresql/schema.pyi index a706c7143..99eccb6ff 100644 --- a/django-stubs/db/backends/postgresql/schema.pyi +++ b/django-stubs/db/backends/postgresql/schema.pyi @@ -2,6 +2,8 @@ from typing import Any from django.db.backends.base.schema import BaseDatabaseSchemaEditor from django.db.backends.postgresql.base import DatabaseWrapper +from django.db.models.base import Model +from django.db.models.indexes import Index class DatabaseSchemaEditor(BaseDatabaseSchemaEditor): connection: DatabaseWrapper @@ -17,5 +19,5 @@ class DatabaseSchemaEditor(BaseDatabaseSchemaEditor): sql_delete_fk: str sql_delete_procedure: str def quote_value(self, value: Any) -> str: ... - def add_index(self, model: Any, index: Any, concurrently: bool = ...) -> None: ... - def remove_index(self, model: Any, index: Any, concurrently: bool = ...) -> None: ... + def add_index(self, model: type[Model], index: Index, concurrently: bool = ...) -> None: ... + def remove_index(self, model: type[Model], index: Index, concurrently: bool = ...) -> None: ...