From 31ef26eee154c0dacd86ef0a60c2c166bea04adc Mon Sep 17 00:00:00 2001 From: Christian Bundy Date: Sun, 22 Jan 2023 15:55:17 -0800 Subject: [PATCH 01/36] Fix admin action return type --- django-stubs/contrib/admin/decorators.pyi | 9 +++++---- django-stubs/contrib/admin/options.pyi | 2 +- 2 files changed, 6 insertions(+), 5 deletions(-) diff --git a/django-stubs/contrib/admin/decorators.pyi b/django-stubs/contrib/admin/decorators.pyi index adcad67ad..e44da0fff 100644 --- a/django-stubs/contrib/admin/decorators.pyi +++ b/django-stubs/contrib/admin/decorators.pyi @@ -1,12 +1,12 @@ from collections.abc import Callable, Sequence -from typing import Any, TypeVar, Union, overload # noqa: Y037 +from typing import Any, Optional, TypeVar, Union, overload # noqa: Y037 from django.contrib.admin import ModelAdmin from django.contrib.admin.sites import AdminSite from django.db.models import Combinable, QuerySet from django.db.models.base import Model from django.db.models.expressions import BaseExpression -from django.http import HttpRequest +from django.http import HttpRequest, HttpResponse from django.utils.functional import _StrOrPromise from typing_extensions import TypeAlias @@ -17,20 +17,21 @@ _QuerySet = TypeVar("_QuerySet", bound=QuerySet) # This is deliberately different from _DisplayT defined in contrib.admin.options _DisplayCallable: TypeAlias = Union[Callable[[_ModelAdmin, _Model], Any], Callable[[_Model], Any]] # noqa: Y037 _DisplayCallableT = TypeVar("_DisplayCallableT", bound=_DisplayCallable) +_ActionReturn = TypeVar("_ActionReturn", bound=Optional[HttpResponse]) @overload def action( function: Callable[[_ModelAdmin, _Request, _QuerySet], None], permissions: Sequence[str] | None = ..., description: _StrOrPromise | None = ..., -) -> Callable[[_ModelAdmin, _Request, _QuerySet], None]: ... +) -> Callable[[_ModelAdmin, _Request, _QuerySet], Optional[HttpResponse]]: ... @overload def action( *, permissions: Sequence[str] | None = ..., description: _StrOrPromise | None = ..., ) -> Callable[ - [Callable[[_ModelAdmin, _Request, _QuerySet], None]], Callable[[_ModelAdmin, _Request, _QuerySet], None] + [Callable[[_ModelAdmin, _Request, _QuerySet], _ActionReturn]], Callable[[_ModelAdmin, _Request, _QuerySet], _ActionReturn] ]: ... @overload def display( diff --git a/django-stubs/contrib/admin/options.pyi b/django-stubs/contrib/admin/options.pyi index af42ea939..45a72abc7 100644 --- a/django-stubs/contrib/admin/options.pyi +++ b/django-stubs/contrib/admin/options.pyi @@ -131,7 +131,7 @@ class BaseModelAdmin(Generic[_ModelT]): _DisplayT: TypeAlias = _ListOrTuple[str | Callable[[_ModelT], str | bool]] _ModelAdmin = TypeVar("_ModelAdmin", bound=ModelAdmin) -_ActionCallable: TypeAlias = Callable[[_ModelAdmin, HttpRequest, QuerySet[_ModelT]], None] +_ActionCallable: TypeAlias = Callable[[_ModelAdmin, HttpRequest, QuerySet[_ModelT]], Optional[HttpResponse]] class ModelAdmin(BaseModelAdmin[_ModelT]): list_display: _DisplayT From c089372432405f5b22bf528f016ea930d2668a2f Mon Sep 17 00:00:00 2001 From: "pre-commit-ci[bot]" <66853113+pre-commit-ci[bot]@users.noreply.github.com> Date: Sun, 22 Jan 2023 23:58:31 +0000 Subject: [PATCH 02/36] [pre-commit.ci] auto fixes from pre-commit.com hooks --- django-stubs/contrib/admin/decorators.pyi | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/django-stubs/contrib/admin/decorators.pyi b/django-stubs/contrib/admin/decorators.pyi index e44da0fff..3d256d503 100644 --- a/django-stubs/contrib/admin/decorators.pyi +++ b/django-stubs/contrib/admin/decorators.pyi @@ -31,7 +31,8 @@ def action( permissions: Sequence[str] | None = ..., description: _StrOrPromise | None = ..., ) -> Callable[ - [Callable[[_ModelAdmin, _Request, _QuerySet], _ActionReturn]], Callable[[_ModelAdmin, _Request, _QuerySet], _ActionReturn] + [Callable[[_ModelAdmin, _Request, _QuerySet], _ActionReturn]], + Callable[[_ModelAdmin, _Request, _QuerySet], _ActionReturn], ]: ... @overload def display( From 3fe1a91fd92839dbdf938958181c8509f44e892b Mon Sep 17 00:00:00 2001 From: Christian Bundy Date: Sun, 22 Jan 2023 16:14:27 -0800 Subject: [PATCH 03/36] Use HttpResponseBase to support StreamingHttpResponse --- django-stubs/contrib/admin/decorators.pyi | 2 +- django-stubs/contrib/admin/options.pyi | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/django-stubs/contrib/admin/decorators.pyi b/django-stubs/contrib/admin/decorators.pyi index 3d256d503..bb11d9108 100644 --- a/django-stubs/contrib/admin/decorators.pyi +++ b/django-stubs/contrib/admin/decorators.pyi @@ -6,7 +6,7 @@ from django.contrib.admin.sites import AdminSite from django.db.models import Combinable, QuerySet from django.db.models.base import Model from django.db.models.expressions import BaseExpression -from django.http import HttpRequest, HttpResponse +from django.http import HttpRequest, HttpResponseBase from django.utils.functional import _StrOrPromise from typing_extensions import TypeAlias diff --git a/django-stubs/contrib/admin/options.pyi b/django-stubs/contrib/admin/options.pyi index 45a72abc7..ebf2d8bb7 100644 --- a/django-stubs/contrib/admin/options.pyi +++ b/django-stubs/contrib/admin/options.pyi @@ -27,7 +27,7 @@ from django.forms.models import ( ) from django.forms.widgets import Media from django.http.request import HttpRequest -from django.http.response import HttpResponse, HttpResponseRedirect +from django.http.response import HttpResponse, HttpResponseRedirect, HttpResponseBase from django.template.response import _TemplateForResponseT from django.urls.resolvers import URLPattern from django.utils.datastructures import _ListOrTuple @@ -131,7 +131,7 @@ class BaseModelAdmin(Generic[_ModelT]): _DisplayT: TypeAlias = _ListOrTuple[str | Callable[[_ModelT], str | bool]] _ModelAdmin = TypeVar("_ModelAdmin", bound=ModelAdmin) -_ActionCallable: TypeAlias = Callable[[_ModelAdmin, HttpRequest, QuerySet[_ModelT]], Optional[HttpResponse]] +_ActionCallable: TypeAlias = Callable[[_ModelAdmin, HttpRequest, QuerySet[_ModelT]], Optional[HttpResponseBase]] class ModelAdmin(BaseModelAdmin[_ModelT]): list_display: _DisplayT From 5bc0daafd839de18ad29e161b20b1088d8a65158 Mon Sep 17 00:00:00 2001 From: "pre-commit-ci[bot]" <66853113+pre-commit-ci[bot]@users.noreply.github.com> Date: Mon, 23 Jan 2023 00:14:54 +0000 Subject: [PATCH 04/36] [pre-commit.ci] auto fixes from pre-commit.com hooks --- django-stubs/contrib/admin/options.pyi | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/django-stubs/contrib/admin/options.pyi b/django-stubs/contrib/admin/options.pyi index ebf2d8bb7..9581fff66 100644 --- a/django-stubs/contrib/admin/options.pyi +++ b/django-stubs/contrib/admin/options.pyi @@ -27,7 +27,7 @@ from django.forms.models import ( ) from django.forms.widgets import Media from django.http.request import HttpRequest -from django.http.response import HttpResponse, HttpResponseRedirect, HttpResponseBase +from django.http.response import HttpResponse, HttpResponseBase, HttpResponseRedirect from django.template.response import _TemplateForResponseT from django.urls.resolvers import URLPattern from django.utils.datastructures import _ListOrTuple From a71a4249494943f7bfdc71b43340ab7623d1fc34 Mon Sep 17 00:00:00 2001 From: Christian Bundy Date: Sun, 22 Jan 2023 21:13:38 -0800 Subject: [PATCH 05/36] Fix usage --- django-stubs/contrib/admin/decorators.pyi | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/django-stubs/contrib/admin/decorators.pyi b/django-stubs/contrib/admin/decorators.pyi index bb11d9108..e98e122f9 100644 --- a/django-stubs/contrib/admin/decorators.pyi +++ b/django-stubs/contrib/admin/decorators.pyi @@ -17,14 +17,14 @@ _QuerySet = TypeVar("_QuerySet", bound=QuerySet) # This is deliberately different from _DisplayT defined in contrib.admin.options _DisplayCallable: TypeAlias = Union[Callable[[_ModelAdmin, _Model], Any], Callable[[_Model], Any]] # noqa: Y037 _DisplayCallableT = TypeVar("_DisplayCallableT", bound=_DisplayCallable) -_ActionReturn = TypeVar("_ActionReturn", bound=Optional[HttpResponse]) +_ActionReturn = TypeVar("_ActionReturn", bound=Optional[HttpResponseBase]) @overload def action( function: Callable[[_ModelAdmin, _Request, _QuerySet], None], permissions: Sequence[str] | None = ..., description: _StrOrPromise | None = ..., -) -> Callable[[_ModelAdmin, _Request, _QuerySet], Optional[HttpResponse]]: ... +) -> Callable[[_ModelAdmin, _Request, _QuerySet], Optional[HttpResponseBase]]: ... @overload def action( *, From aa9dea3310f40c73c89da5bf39a786500b0aabfd Mon Sep 17 00:00:00 2001 From: Christian Bundy Date: Mon, 23 Jan 2023 08:46:06 -0800 Subject: [PATCH 06/36] Fix issues --- django-stubs/contrib/admin/decorators.pyi | 14 ++++++-------- tests/typecheck/contrib/admin/test_decorators.yml | 15 ++++++++++++++- tests/typecheck/contrib/admin/test_options.yml | 2 +- 3 files changed, 21 insertions(+), 10 deletions(-) diff --git a/django-stubs/contrib/admin/decorators.pyi b/django-stubs/contrib/admin/decorators.pyi index e98e122f9..2876e34c9 100644 --- a/django-stubs/contrib/admin/decorators.pyi +++ b/django-stubs/contrib/admin/decorators.pyi @@ -1,5 +1,5 @@ from collections.abc import Callable, Sequence -from typing import Any, Optional, TypeVar, Union, overload # noqa: Y037 +from typing import Any, TypeVar, Union, overload # noqa: Y037 from django.contrib.admin import ModelAdmin from django.contrib.admin.sites import AdminSite @@ -17,23 +17,21 @@ _QuerySet = TypeVar("_QuerySet", bound=QuerySet) # This is deliberately different from _DisplayT defined in contrib.admin.options _DisplayCallable: TypeAlias = Union[Callable[[_ModelAdmin, _Model], Any], Callable[[_Model], Any]] # noqa: Y037 _DisplayCallableT = TypeVar("_DisplayCallableT", bound=_DisplayCallable) -_ActionReturn = TypeVar("_ActionReturn", bound=Optional[HttpResponseBase]) +_ActionCallable: TypeAlias = Callable[[_ModelAdmin, _Request, _QuerySet], HttpResponseBase | None] # noqa: Y037 +_ActionCallableT = TypeVar("_ActionCallableT", bound=_ActionCallable) @overload def action( - function: Callable[[_ModelAdmin, _Request, _QuerySet], None], + function: _ActionCallableT, permissions: Sequence[str] | None = ..., description: _StrOrPromise | None = ..., -) -> Callable[[_ModelAdmin, _Request, _QuerySet], Optional[HttpResponseBase]]: ... +) -> _ActionCallableT: ... @overload def action( *, permissions: Sequence[str] | None = ..., description: _StrOrPromise | None = ..., -) -> Callable[ - [Callable[[_ModelAdmin, _Request, _QuerySet], _ActionReturn]], - Callable[[_ModelAdmin, _Request, _QuerySet], _ActionReturn], -]: ... +) -> Callable[[_ActionCallableT], _ActionCallableT,]: ... @overload def display( function: _DisplayCallableT, diff --git a/tests/typecheck/contrib/admin/test_decorators.yml b/tests/typecheck/contrib/admin/test_decorators.yml index 9f16d8f5f..28b3e0b67 100644 --- a/tests/typecheck/contrib/admin/test_decorators.yml +++ b/tests/typecheck/contrib/admin/test_decorators.yml @@ -60,7 +60,7 @@ from django.contrib import admin from django.db.models import QuerySet - from django.http import HttpRequest + from django.http import FileResponse, HttpRequest, HttpResponse class MyModel(models.Model): ... @@ -73,6 +73,11 @@ @admin.action(description="Some text here", permissions=["test"]) def freestanding_action_fancy(modeladmin: "MyModelAdmin", request: HttpRequest, queryset: QuerySet[MyModel]) -> None: ... + @admin.action + def freestanding_action_http_response(modeladmin: "MyModelAdmin", request: HttpRequest, queryset: QuerySet[MyModel]) -> HttpResponse: ... + + @admin.action + def freestanding_action_file_response(modeladmin: "MyModelAdmin", request: HttpRequest, queryset: QuerySet[MyModel]) -> FileResponse: ... @admin.register(MyModel) class MyModelAdmin(admin.ModelAdmin[MyModel]): @@ -84,6 +89,14 @@ @admin.action(description="Some text here", permissions=["test"]) def method_action_fancy(self, request: HttpRequest, queryset: QuerySet[MyModel]) -> None: ... + @admin.action(description="Some text here", permissions=["test"]) + def method_action_http_response(self, request: HttpRequest, queryset: QuerySet[MyModel]) -> HttpResponse: ... + + @admin.action(description="Some text here", permissions=["test"]) + def method_action_file_response(self, request: HttpRequest, queryset: QuerySet[MyModel]) -> FileResponse: ... + def method(self) -> None: reveal_type(self.method_action_bare) # N: Revealed type is "def (django.http.request.HttpRequest, django.db.models.query._QuerySet[main.MyModel, main.MyModel])" reveal_type(self.method_action_fancy) # N: Revealed type is "def (django.http.request.HttpRequest, django.db.models.query._QuerySet[main.MyModel, main.MyModel])" + reveal_type(self.method_action_http_response) # N: Revealed type is "def (django.http.request.HttpRequest, django.db.models.query._QuerySet[main.MyModel, main.MyModel]) -> django.http.response.HttpResponse" + reveal_type(self.method_action_file_response) # N: Revealed type is "def (django.http.request.HttpRequest, django.db.models.query._QuerySet[main.MyModel, main.MyModel]) -> django.http.response.FileResponse" diff --git a/tests/typecheck/contrib/admin/test_options.yml b/tests/typecheck/contrib/admin/test_options.yml index 4e9bd7e64..18cfeb19c 100644 --- a/tests/typecheck/contrib/admin/test_options.yml +++ b/tests/typecheck/contrib/admin/test_options.yml @@ -140,7 +140,7 @@ pass class A(admin.ModelAdmin): - actions = [an_action] # E: List item 0 has incompatible type "Callable[[None], None]"; expected "Union[Callable[[Any, HttpRequest, _QuerySet[Any, Any]], None], str]" + actions = [an_action] # E: List item 0 has incompatible type "Callable[[None], None]"; expected "Union[Callable[[Any, HttpRequest, _QuerySet[Any, Any]], Optional[HttpResponseBase]], str]" - case: errors_for_invalid_model_admin_generic main: | from django.contrib.admin import ModelAdmin From 92da2c19808422f3e7373b9c6f605c6120c043dd Mon Sep 17 00:00:00 2001 From: Christian Bundy Date: Mon, 23 Jan 2023 09:07:15 -0800 Subject: [PATCH 07/36] Fix test --- tests/typecheck/contrib/admin/test_decorators.yml | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/tests/typecheck/contrib/admin/test_decorators.yml b/tests/typecheck/contrib/admin/test_decorators.yml index 28b3e0b67..0a5ad159a 100644 --- a/tests/typecheck/contrib/admin/test_decorators.yml +++ b/tests/typecheck/contrib/admin/test_decorators.yml @@ -96,7 +96,7 @@ def method_action_file_response(self, request: HttpRequest, queryset: QuerySet[MyModel]) -> FileResponse: ... def method(self) -> None: - reveal_type(self.method_action_bare) # N: Revealed type is "def (django.http.request.HttpRequest, django.db.models.query._QuerySet[main.MyModel, main.MyModel])" - reveal_type(self.method_action_fancy) # N: Revealed type is "def (django.http.request.HttpRequest, django.db.models.query._QuerySet[main.MyModel, main.MyModel])" - reveal_type(self.method_action_http_response) # N: Revealed type is "def (django.http.request.HttpRequest, django.db.models.query._QuerySet[main.MyModel, main.MyModel]) -> django.http.response.HttpResponse" - reveal_type(self.method_action_file_response) # N: Revealed type is "def (django.http.request.HttpRequest, django.db.models.query._QuerySet[main.MyModel, main.MyModel]) -> django.http.response.FileResponse" + reveal_type(self.method_action_bare) # N: Revealed type is "def (request: django.http.request.HttpRequest, queryset: django.db.models.query._QuerySet[main.MyModel, main.MyModel])" + reveal_type(self.method_action_fancy) # N: Revealed type is "def (request: django.http.request.HttpRequest, queryset: django.db.models.query._QuerySet[main.MyModel, main.MyModel])" + reveal_type(self.method_action_http_response) # N: Revealed type is "def (request: django.http.request.HttpRequest, queryset: django.db.models.query._QuerySet[main.MyModel, main.MyModel]) -> django.http.response.HttpResponse" + reveal_type(self.method_action_file_response) # N: Revealed type is "def (request: django.http.request.HttpRequest, queryset: django.db.models.query._QuerySet[main.MyModel, main.MyModel]) -> django.http.response.FileResponse" From d004b1b721daf8003f2ad6b9f734698f51b4a302 Mon Sep 17 00:00:00 2001 From: Christian Bundy Date: Mon, 23 Jan 2023 14:49:31 -0800 Subject: [PATCH 08/36] Remove redundant comma Co-authored-by: Marti Raudsepp --- django-stubs/contrib/admin/decorators.pyi | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/django-stubs/contrib/admin/decorators.pyi b/django-stubs/contrib/admin/decorators.pyi index 2876e34c9..03a15b3d8 100644 --- a/django-stubs/contrib/admin/decorators.pyi +++ b/django-stubs/contrib/admin/decorators.pyi @@ -31,7 +31,7 @@ def action( *, permissions: Sequence[str] | None = ..., description: _StrOrPromise | None = ..., -) -> Callable[[_ActionCallableT], _ActionCallableT,]: ... +) -> Callable[[_ActionCallableT], _ActionCallableT]: ... @overload def display( function: _DisplayCallableT, From 3fa57f03709828e43f576fee94325191976c3e9b Mon Sep 17 00:00:00 2001 From: Christian Bundy Date: Mon, 23 Jan 2023 14:50:00 -0800 Subject: [PATCH 09/36] Use `T | None` rather than `Optional[T]` Co-authored-by: Marti Raudsepp --- django-stubs/contrib/admin/options.pyi | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/django-stubs/contrib/admin/options.pyi b/django-stubs/contrib/admin/options.pyi index 9581fff66..994485ba5 100644 --- a/django-stubs/contrib/admin/options.pyi +++ b/django-stubs/contrib/admin/options.pyi @@ -131,7 +131,7 @@ class BaseModelAdmin(Generic[_ModelT]): _DisplayT: TypeAlias = _ListOrTuple[str | Callable[[_ModelT], str | bool]] _ModelAdmin = TypeVar("_ModelAdmin", bound=ModelAdmin) -_ActionCallable: TypeAlias = Callable[[_ModelAdmin, HttpRequest, QuerySet[_ModelT]], Optional[HttpResponseBase]] +_ActionCallable: TypeAlias = Callable[[_ModelAdmin, HttpRequest, QuerySet[_ModelT]], HttpResponseBase | None] class ModelAdmin(BaseModelAdmin[_ModelT]): list_display: _DisplayT From 66e29c9c794bd70ed3fb44de90be21d02acce57c Mon Sep 17 00:00:00 2001 From: Christian Bundy Date: Mon, 23 Jan 2023 14:59:55 -0800 Subject: [PATCH 10/36] Add freestanding actions to test --- tests/typecheck/contrib/admin/test_decorators.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/typecheck/contrib/admin/test_decorators.yml b/tests/typecheck/contrib/admin/test_decorators.yml index 0a5ad159a..4e8335c9c 100644 --- a/tests/typecheck/contrib/admin/test_decorators.yml +++ b/tests/typecheck/contrib/admin/test_decorators.yml @@ -81,7 +81,7 @@ @admin.register(MyModel) class MyModelAdmin(admin.ModelAdmin[MyModel]): - actions = [freestanding_action_bare, freestanding_action_fancy, "method_action_bare", "method_action_fancy"] + actions = [freestanding_action_bare, freestanding_action_fancy, "method_action_bare", "method_action_fancy", freestanding_action_http_response, freestanding_action_file_response] @admin.action def method_action_bare(self, request: HttpRequest, queryset: QuerySet[MyModel]) -> None: ... From 0477a2641f70e5712b826385f1d024148ee788e0 Mon Sep 17 00:00:00 2001 From: Christian Bundy Date: Mon, 23 Jan 2023 15:03:53 -0800 Subject: [PATCH 11/36] Add negative test cases --- tests/typecheck/contrib/admin/test_decorators.yml | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/tests/typecheck/contrib/admin/test_decorators.yml b/tests/typecheck/contrib/admin/test_decorators.yml index 4e8335c9c..7f4fb63e2 100644 --- a/tests/typecheck/contrib/admin/test_decorators.yml +++ b/tests/typecheck/contrib/admin/test_decorators.yml @@ -79,6 +79,9 @@ @admin.action def freestanding_action_file_response(modeladmin: "MyModelAdmin", request: HttpRequest, queryset: QuerySet[MyModel]) -> FileResponse: ... + @admin.action # E: Value of type variable "_ActionCallableT" of "action" cannot be "Callable[[MyModelAdmin, HttpRequest, _QuerySet[MyModel, MyModel]], bool]" + def freestanding_action_invalid(modeladmin: "MyModelAdmin", request: HttpRequest, queryset: QuerySet[MyModel]) -> bool: ... + @admin.register(MyModel) class MyModelAdmin(admin.ModelAdmin[MyModel]): actions = [freestanding_action_bare, freestanding_action_fancy, "method_action_bare", "method_action_fancy", freestanding_action_http_response, freestanding_action_file_response] @@ -95,6 +98,9 @@ @admin.action(description="Some text here", permissions=["test"]) def method_action_file_response(self, request: HttpRequest, queryset: QuerySet[MyModel]) -> FileResponse: ... + @admin.action(description="Some text here", permissions=["test"]) # E: Value of type variable "_ActionCallableT" of function cannot be "Callable[[MyModelAdmin, HttpRequest, _QuerySet[MyModel, MyModel]], int]" + def method_action_invalid(self, request: HttpRequest, queryset: QuerySet[MyModel]) -> int: ... + def method(self) -> None: reveal_type(self.method_action_bare) # N: Revealed type is "def (request: django.http.request.HttpRequest, queryset: django.db.models.query._QuerySet[main.MyModel, main.MyModel])" reveal_type(self.method_action_fancy) # N: Revealed type is "def (request: django.http.request.HttpRequest, queryset: django.db.models.query._QuerySet[main.MyModel, main.MyModel])" From ea49719c6671d21ab71885f0c8cc0f0805686103 Mon Sep 17 00:00:00 2001 From: Christian Bundy Date: Mon, 23 Jan 2023 15:37:29 -0800 Subject: [PATCH 12/36] Add unhappier paths and fix problems --- django-stubs/contrib/admin/decorators.pyi | 12 +++++----- .../contrib/admin/test_decorators.yml | 22 ++++++++++++------- 2 files changed, 21 insertions(+), 13 deletions(-) diff --git a/django-stubs/contrib/admin/decorators.pyi b/django-stubs/contrib/admin/decorators.pyi index 03a15b3d8..66664f37f 100644 --- a/django-stubs/contrib/admin/decorators.pyi +++ b/django-stubs/contrib/admin/decorators.pyi @@ -17,21 +17,23 @@ _QuerySet = TypeVar("_QuerySet", bound=QuerySet) # This is deliberately different from _DisplayT defined in contrib.admin.options _DisplayCallable: TypeAlias = Union[Callable[[_ModelAdmin, _Model], Any], Callable[[_Model], Any]] # noqa: Y037 _DisplayCallableT = TypeVar("_DisplayCallableT", bound=_DisplayCallable) -_ActionCallable: TypeAlias = Callable[[_ModelAdmin, _Request, _QuerySet], HttpResponseBase | None] # noqa: Y037 -_ActionCallableT = TypeVar("_ActionCallableT", bound=_ActionCallable) +_ActionReturn = TypeVar("_ActionReturn", bound=HttpResponseBase | None) @overload def action( - function: _ActionCallableT, + function: Callable[[_ModelAdmin, _Request, _QuerySet], _ActionReturn], permissions: Sequence[str] | None = ..., description: _StrOrPromise | None = ..., -) -> _ActionCallableT: ... +) -> Callable[[_ModelAdmin, _Request, _QuerySet], _ActionReturn]: ... @overload def action( *, permissions: Sequence[str] | None = ..., description: _StrOrPromise | None = ..., -) -> Callable[[_ActionCallableT], _ActionCallableT]: ... +) -> Callable[ + [Callable[[_ModelAdmin, _Request, _QuerySet], _ActionReturn]], + Callable[[_ModelAdmin, _Request, _QuerySet], _ActionReturn], +]: ... @overload def display( function: _DisplayCallableT, diff --git a/tests/typecheck/contrib/admin/test_decorators.yml b/tests/typecheck/contrib/admin/test_decorators.yml index 7f4fb63e2..2b21443e0 100644 --- a/tests/typecheck/contrib/admin/test_decorators.yml +++ b/tests/typecheck/contrib/admin/test_decorators.yml @@ -79,8 +79,11 @@ @admin.action def freestanding_action_file_response(modeladmin: "MyModelAdmin", request: HttpRequest, queryset: QuerySet[MyModel]) -> FileResponse: ... - @admin.action # E: Value of type variable "_ActionCallableT" of "action" cannot be "Callable[[MyModelAdmin, HttpRequest, _QuerySet[MyModel, MyModel]], bool]" - def freestanding_action_invalid(modeladmin: "MyModelAdmin", request: HttpRequest, queryset: QuerySet[MyModel]) -> bool: ... + @admin.action # E: Value of type variable "_ModelAdmin" of "action" cannot be "int" + def freestanding_action_invalid_bare(modeladmin: int, request: HttpRequest, queryset: QuerySet[MyModel]) -> None: ... + + @admin.action(description="Some text here", permissions=["test"]) # E: Value of type variable "_ModelAdmin" of function cannot be "int" + def freestanding_action_invalid_fancy(modeladmin: int, request: HttpRequest, queryset: QuerySet[MyModel]) -> None: ... @admin.register(MyModel) class MyModelAdmin(admin.ModelAdmin[MyModel]): @@ -98,11 +101,14 @@ @admin.action(description="Some text here", permissions=["test"]) def method_action_file_response(self, request: HttpRequest, queryset: QuerySet[MyModel]) -> FileResponse: ... - @admin.action(description="Some text here", permissions=["test"]) # E: Value of type variable "_ActionCallableT" of function cannot be "Callable[[MyModelAdmin, HttpRequest, _QuerySet[MyModel, MyModel]], int]" - def method_action_invalid(self, request: HttpRequest, queryset: QuerySet[MyModel]) -> int: ... + @admin.action # E: Value of type variable "_QuerySet" of "action" cannot be "int" + def method_action_invalid_bare(self, request: HttpRequest, queryset: int) -> None: ... + + @admin.action(description="Some text here", permissions=["test"]) # E: Value of type variable "_QuerySet" of function cannot be "int" + def method_action_invalid_fancy(self, request: HttpRequest, queryset: int) -> None: ... def method(self) -> None: - reveal_type(self.method_action_bare) # N: Revealed type is "def (request: django.http.request.HttpRequest, queryset: django.db.models.query._QuerySet[main.MyModel, main.MyModel])" - reveal_type(self.method_action_fancy) # N: Revealed type is "def (request: django.http.request.HttpRequest, queryset: django.db.models.query._QuerySet[main.MyModel, main.MyModel])" - reveal_type(self.method_action_http_response) # N: Revealed type is "def (request: django.http.request.HttpRequest, queryset: django.db.models.query._QuerySet[main.MyModel, main.MyModel]) -> django.http.response.HttpResponse" - reveal_type(self.method_action_file_response) # N: Revealed type is "def (request: django.http.request.HttpRequest, queryset: django.db.models.query._QuerySet[main.MyModel, main.MyModel]) -> django.http.response.FileResponse" + reveal_type(self.method_action_bare) # N: Revealed type is "def (django.http.request.HttpRequest, django.db.models.query._QuerySet[main.MyModel, main.MyModel])" + reveal_type(self.method_action_fancy) # N: Revealed type is "def (django.http.request.HttpRequest, django.db.models.query._QuerySet[main.MyModel, main.MyModel])" + reveal_type(self.method_action_http_response) # N: Revealed type is "def (django.http.request.HttpRequest, django.db.models.query._QuerySet[main.MyModel, main.MyModel]) -> django.http.response.HttpResponse" + reveal_type(self.method_action_file_response) # N: Revealed type is "def (django.http.request.HttpRequest, django.db.models.query._QuerySet[main.MyModel, main.MyModel]) -> django.http.response.FileResponse" From 0494aa522996d92d130edc3f4a5a0ad364172f7c Mon Sep 17 00:00:00 2001 From: Christian Bundy Date: Mon, 23 Jan 2023 21:52:00 -0800 Subject: [PATCH 13/36] Fix Field --- django-stubs/apps/registry.pyi | 2 +- django-stubs/conf/urls/static.pyi | 2 +- django-stubs/contrib/admin/filters.pyi | 10 +++--- django-stubs/contrib/admin/helpers.pyi | 4 +-- django-stubs/contrib/admin/options.pyi | 18 ++++++---- django-stubs/contrib/admin/sites.pyi | 4 +-- .../contrib/admin/templatetags/admin_list.pyi | 6 ++-- .../contrib/admin/templatetags/base.pyi | 4 +-- django-stubs/contrib/admin/tests.pyi | 2 +- django-stubs/contrib/admin/utils.pyi | 24 ++++++------- .../contrib/admin/views/decorators.pyi | 6 ++-- django-stubs/contrib/admin/views/main.pyi | 2 +- django-stubs/contrib/admindocs/utils.pyi | 2 +- django-stubs/contrib/admindocs/views.pyi | 4 +-- django-stubs/contrib/auth/forms.pyi | 2 +- django-stubs/contrib/auth/hashers.pyi | 4 ++- django-stubs/contrib/auth/mixins.pyi | 2 +- django-stubs/contrib/contenttypes/fields.pyi | 4 +-- django-stubs/contrib/gis/db/models/fields.pyi | 18 +++++----- .../contrib/gis/utils/layermapping.pyi | 4 +-- .../humanize/templatetags/humanize.pyi | 2 +- .../contrib/postgres/fields/array.pyi | 4 +-- .../contrib/postgres/fields/hstore.pyi | 2 +- .../contrib/postgres/fields/ranges.pyi | 8 ++--- django-stubs/contrib/postgres/search.pyi | 14 ++++---- django-stubs/contrib/sitemaps/views.pyi | 4 +-- django-stubs/contrib/staticfiles/storage.pyi | 2 +- django-stubs/core/cache/backends/base.pyi | 4 +-- django-stubs/core/management/base.pyi | 4 +-- django-stubs/core/serializers/__init__.pyi | 2 +- django-stubs/core/serializers/base.pyi | 4 +-- django-stubs/core/serializers/pyyaml.pyi | 2 +- django-stubs/db/backends/base/operations.pyi | 2 +- django-stubs/db/backends/base/schema.pyi | 8 +++-- django-stubs/db/backends/base/validation.pyi | 2 +- django-stubs/db/migrations/autodetector.pyi | 4 +-- .../db/migrations/operations/fields.pyi | 12 ++++--- .../db/migrations/operations/models.pyi | 4 +-- .../db/migrations/operations/special.pyi | 4 +-- .../db/migrations/operations/utils.pyi | 13 ++++--- django-stubs/db/migrations/questioner.pyi | 2 +- django-stubs/db/migrations/serializer.pyi | 2 +- django-stubs/db/migrations/state.pyi | 4 +-- django-stubs/db/models/deletion.pyi | 12 +++---- django-stubs/db/models/expressions.pyi | 36 ++++++++++--------- django-stubs/db/models/fields/__init__.pyi | 2 +- django-stubs/db/models/fields/files.pyi | 2 +- django-stubs/db/models/fields/json.pyi | 2 +- django-stubs/db/models/fields/related.pyi | 12 +++---- .../db/models/fields/related_descriptors.pyi | 8 ++--- .../db/models/fields/related_lookups.pyi | 14 +++++--- .../db/models/fields/reverse_related.pyi | 12 +++---- .../db/models/functions/comparison.pyi | 2 +- django-stubs/db/models/options.pyi | 14 ++++---- django-stubs/db/models/query_utils.pyi | 6 ++-- django-stubs/db/models/signals.pyi | 4 +-- django-stubs/db/models/sql/compiler.pyi | 6 ++-- django-stubs/db/models/sql/query.pyi | 14 ++++---- django-stubs/db/models/sql/subqueries.pyi | 8 ++--- django-stubs/db/transaction.pyi | 4 +-- django-stubs/dispatch/dispatcher.pyi | 14 +++++--- django-stubs/forms/fields.pyi | 2 +- django-stubs/forms/forms.pyi | 2 +- django-stubs/forms/models.pyi | 4 +-- django-stubs/forms/widgets.pyi | 2 +- django-stubs/middleware/cache.pyi | 2 +- django-stubs/middleware/csrf.pyi | 6 +++- django-stubs/shortcuts.pyi | 8 ++--- django-stubs/template/backends/jinja2.pyi | 2 +- django-stubs/template/base.pyi | 8 ++--- django-stubs/template/context.pyi | 2 +- django-stubs/template/context_processors.pyi | 4 +-- django-stubs/template/defaultfilters.pyi | 2 +- django-stubs/template/engine.pyi | 2 +- django-stubs/template/library.pyi | 16 ++++----- django-stubs/template/response.pyi | 2 +- django-stubs/test/testcases.pyi | 14 ++++---- django-stubs/test/utils.pyi | 20 ++++++----- django-stubs/urls/base.pyi | 2 +- django-stubs/urls/resolvers.pyi | 10 +++--- django-stubs/urls/utils.pyi | 3 +- django-stubs/utils/asyncio.pyi | 2 +- django-stubs/utils/autoreload.pyi | 4 +-- django-stubs/utils/crypto.pyi | 3 +- django-stubs/utils/decorators.pyi | 16 +++++---- django-stubs/utils/deprecation.pyi | 2 +- django-stubs/utils/feedgenerator.pyi | 2 +- django-stubs/utils/functional.pyi | 32 ++++++++--------- django-stubs/utils/log.pyi | 4 +-- django-stubs/utils/safestring.pyi | 2 +- django-stubs/utils/termcolors.pyi | 2 +- django-stubs/utils/translation/__init__.pyi | 24 ++++++------- django-stubs/views/debug.pyi | 2 +- django-stubs/views/decorators/cache.pyi | 6 ++-- django-stubs/views/decorators/debug.pyi | 4 +-- django-stubs/views/decorators/http.pyi | 4 ++- django-stubs/views/decorators/vary.pyi | 2 +- django-stubs/views/i18n.pyi | 2 +- mypy.ini | 1 + tests/typecheck/db/models/test_init.yml | 2 +- 100 files changed, 340 insertions(+), 294 deletions(-) diff --git a/django-stubs/apps/registry.pyi b/django-stubs/apps/registry.pyi index 528704e31..3d4175708 100644 --- a/django-stubs/apps/registry.pyi +++ b/django-stubs/apps/registry.pyi @@ -35,7 +35,7 @@ class Apps: def set_installed_apps(self, installed: Iterable[str]) -> None: ... def unset_installed_apps(self) -> None: ... def clear_cache(self) -> None: ... - def lazy_model_operation(self, function: Callable, *model_keys: Any) -> None: ... + def lazy_model_operation(self, function: Callable[..., Any], *model_keys: Any) -> None: ... def do_pending_operations(self, model: type[Model]) -> None: ... apps: Apps diff --git a/django-stubs/conf/urls/static.pyi b/django-stubs/conf/urls/static.pyi index f658cace7..78510c79e 100644 --- a/django-stubs/conf/urls/static.pyi +++ b/django-stubs/conf/urls/static.pyi @@ -3,4 +3,4 @@ from typing import Any from django.urls.resolvers import URLPattern -def static(prefix: str, view: Callable = ..., **kwargs: Any) -> list[URLPattern]: ... +def static(prefix: str, view: Callable[..., Any] = ..., **kwargs: Any) -> list[URLPattern]: ... diff --git a/django-stubs/contrib/admin/filters.pyi b/django-stubs/contrib/admin/filters.pyi index b42d689db..9fd530360 100644 --- a/django-stubs/contrib/admin/filters.pyi +++ b/django-stubs/contrib/admin/filters.pyi @@ -29,12 +29,12 @@ class SimpleListFilter(ListFilter): def choices(self, changelist: Any) -> Iterator[dict[str, Any]]: ... class FieldListFilter(ListFilter): - field: Field + field: Field[Any, Any] field_path: str title: str def __init__( self, - field: Field, + field: Field[Any, Any], request: HttpRequest, params: dict[str, str], model: type[Model], @@ -42,11 +42,13 @@ class FieldListFilter(ListFilter): field_path: str, ) -> None: ... @classmethod - def register(cls, test: Callable, list_filter_class: type[FieldListFilter], take_priority: bool = ...) -> None: ... + def register( + cls, test: Callable[..., Any], list_filter_class: type[FieldListFilter], take_priority: bool = ... + ) -> None: ... @classmethod def create( cls, - field: Field, + field: Field[Any, Any], request: HttpRequest, params: dict[str, str], model: type[Model], diff --git a/django-stubs/contrib/admin/helpers.pyi b/django-stubs/contrib/admin/helpers.pyi index e9e916f06..420f73a4f 100644 --- a/django-stubs/contrib/admin/helpers.pyi +++ b/django-stubs/contrib/admin/helpers.pyi @@ -23,7 +23,7 @@ checkbox: Any class _PrepopulatedDict(TypedDict): field: BoundField - dependencies: list[BoundField] + dependencies: list[BoundField[Any, Any]] class AdminForm: prepopulated_fields: list[_PrepopulatedDict] @@ -80,7 +80,7 @@ class Fieldline: readonly_fields: Sequence[str] | None = ..., model_admin: ModelAdmin | None = ..., ) -> None: ... - def __iter__(self) -> Iterator[AdminField | AdminReadonlyField]: ... + def __iter__(self) -> Iterator[AdminField[Any, Any] | AdminReadonlyField[Any, Any]]: ... def errors(self) -> SafeString: ... class AdminField: diff --git a/django-stubs/contrib/admin/options.pyi b/django-stubs/contrib/admin/options.pyi index 994485ba5..cd8ce0640 100644 --- a/django-stubs/contrib/admin/options.pyi +++ b/django-stubs/contrib/admin/options.pyi @@ -68,8 +68,8 @@ _ListFilterT: TypeAlias = Union[ type[ListFilter], Field, str, - tuple[Field | str, type[FieldListFilter]], - list[Field | str | type[FieldListFilter]], + tuple[Field[Any, Any] | str, type[FieldListFilter]], + list[Field[Any, Any] | str | type[FieldListFilter]], ] # Generic type specifically for models, for use in BaseModelAdmin and subclasses @@ -87,7 +87,7 @@ class BaseModelAdmin(Generic[_ModelT]): filter_horizontal: Sequence[str] radio_fields: Mapping[str, _Direction] prepopulated_fields: dict[str, Sequence[str]] - formfield_overrides: Mapping[type[Field], Mapping[str, Any]] + formfield_overrides: Mapping[type[Field[Any, Any]], Mapping[str, Any]] readonly_fields: Sequence[str] ordering: Sequence[str] | None sortable_by: _ListOrTuple[str] | None @@ -99,15 +99,19 @@ class BaseModelAdmin(Generic[_ModelT]): admin_site: AdminSite def __init__(self) -> None: ... def check(self, **kwargs: Any) -> list[CheckMessage]: ... - def formfield_for_dbfield(self, db_field: Field, request: HttpRequest, **kwargs: Any) -> FormField | None: ... - def formfield_for_choice_field(self, db_field: Field, request: HttpRequest, **kwargs: Any) -> TypedChoiceField: ... + def formfield_for_dbfield( + self, db_field: Field[Any, Any], request: HttpRequest, **kwargs: Any + ) -> FormField | None: ... + def formfield_for_choice_field( + self, db_field: Field[Any, Any], request: HttpRequest, **kwargs: Any + ) -> TypedChoiceField: ... def get_field_queryset(self, db: str | None, db_field: RelatedField, request: HttpRequest) -> QuerySet | None: ... def formfield_for_foreignkey( self, db_field: ForeignKey, request: HttpRequest, **kwargs: Any ) -> ModelChoiceField: ... def formfield_for_manytomany( self, db_field: ManyToManyField, request: HttpRequest, **kwargs: Any - ) -> ModelMultipleChoiceField | None: ... + ) -> ModelMultipleChoiceField[Any, Any] | None: ... def get_autocomplete_fields(self, request: HttpRequest) -> Sequence[str]: ... def get_view_on_site_url(self, obj: _ModelT | None = ...) -> str | None: ... def get_empty_value_display(self) -> SafeString: ... @@ -199,7 +203,7 @@ class ModelAdmin(BaseModelAdmin[_ModelT]): def get_action_choices( self, request: HttpRequest, default_choices: list[tuple[str, str]] = ... ) -> list[tuple[str, str]]: ... - def get_action(self, action: Callable | str) -> tuple[Callable[..., str], str, str] | None: ... + def get_action(self, action: Callable[..., Any] | str) -> tuple[Callable[..., str], str, str] | None: ... def get_list_display(self, request: HttpRequest) -> _DisplayT: ... def get_list_display_links(self, request: HttpRequest, list_display: _DisplayT) -> _DisplayT: ... def get_list_filter(self, request: HttpRequest) -> Sequence[_ListFilterT]: ... diff --git a/django-stubs/contrib/admin/sites.pyi b/django-stubs/contrib/admin/sites.pyi index 1f3d55951..700aa41eb 100644 --- a/django-stubs/contrib/admin/sites.pyi +++ b/django-stubs/contrib/admin/sites.pyi @@ -61,11 +61,11 @@ class AdminSite: def is_registered(self, model: type[Model]) -> bool: ... def add_action(self, action: _ActionCallback, name: str | None = ...) -> None: ... def disable_action(self, name: str) -> None: ... - def get_action(self, name: str) -> Callable: ... + def get_action(self, name: str) -> Callable[..., Any]: ... @property def actions(self) -> Iterable[tuple[str, _ActionCallback]]: ... def has_permission(self, request: HttpRequest) -> bool: ... - def admin_view(self, view: Callable, cacheable: bool = ...) -> Callable: ... + def admin_view(self, view: Callable[..., Any], cacheable: bool = ...) -> Callable[..., Any]: ... def get_urls(self) -> list[URLResolver | URLPattern]: ... @property def urls(self) -> tuple[list[URLResolver | URLPattern], str, str]: ... diff --git a/django-stubs/contrib/admin/templatetags/admin_list.pyi b/django-stubs/contrib/admin/templatetags/admin_list.pyi index 8eb51c31c..7eb3397b3 100644 --- a/django-stubs/contrib/admin/templatetags/admin_list.pyi +++ b/django-stubs/contrib/admin/templatetags/admin_list.pyi @@ -26,10 +26,12 @@ class ResultList(list): def __init__(self, form: ModelForm | None, *items: Any) -> None: ... def results(cl: ChangeList) -> Iterator[ResultList]: ... -def result_hidden_fields(cl: ChangeList) -> Iterator[BoundField]: ... +def result_hidden_fields(cl: ChangeList) -> Iterator[BoundField[Any, Any]]: ... def result_list( cl: ChangeList, -) -> dict[str, list[dict[str, int | str | None]] | list[ResultList] | list[BoundField] | ChangeList | int]: ... +) -> dict[ + str, list[dict[str, int | str | None]] | list[ResultList] | list[BoundField[Any, Any]] | ChangeList | int +]: ... def result_list_tag(parser: Parser, token: Token) -> InclusionAdminNode: ... def date_hierarchy(cl: ChangeList) -> dict[str, Any] | None: ... def date_hierarchy_tag(parser: Parser, token: Token) -> InclusionAdminNode: ... diff --git a/django-stubs/contrib/admin/templatetags/base.pyi b/django-stubs/contrib/admin/templatetags/base.pyi index d0edf2cfd..bc066fb1f 100644 --- a/django-stubs/contrib/admin/templatetags/base.pyi +++ b/django-stubs/contrib/admin/templatetags/base.pyi @@ -8,11 +8,11 @@ from django.utils.safestring import SafeString class InclusionAdminNode(InclusionNode): args: list[Any] - func: Callable + func: Callable[..., Any] kwargs: dict[str, Any] takes_context: bool template_name: str def __init__( - self, parser: Parser, token: Token, func: Callable, template_name: str, takes_context: bool = ... + self, parser: Parser, token: Token, func: Callable[..., Any], template_name: str, takes_context: bool = ... ) -> None: ... def render(self, context: Context) -> SafeString: ... diff --git a/django-stubs/contrib/admin/tests.pyi b/django-stubs/contrib/admin/tests.pyi index 3a9a53232..eff56124c 100644 --- a/django-stubs/contrib/admin/tests.pyi +++ b/django-stubs/contrib/admin/tests.pyi @@ -9,7 +9,7 @@ from django.utils.deprecation import MiddlewareMixin class CSPMiddleware(MiddlewareMixin): ... class AdminSeleniumTestCase(SeleniumTestCase, StaticLiveServerTestCase): - def wait_until(self, callback: Callable, timeout: int = ...) -> None: ... + def wait_until(self, callback: Callable[..., Any], timeout: int = ...) -> None: ... def wait_for_and_switch_to_popup(self, num_windows: int = ..., timeout: int = ...) -> None: ... def wait_for(self, css_selector: str, timeout: int = ...) -> None: ... def wait_for_text(self, css_selector: str, text: str, timeout: int = ...) -> None: ... diff --git a/django-stubs/contrib/admin/utils.pyi b/django-stubs/contrib/admin/utils.pyi index a45479e61..f9e00a2ed 100644 --- a/django-stubs/contrib/admin/utils.pyi +++ b/django-stubs/contrib/admin/utils.pyi @@ -23,8 +23,8 @@ def lookup_needs_distinct(opts: Options, lookup_path: str) -> bool: ... def prepare_lookup_value(key: str, value: datetime.datetime | str) -> bool | datetime.datetime | str: ... def quote(s: int | str | UUID) -> str: ... def unquote(s: str) -> str: ... -def flatten(fields: Any) -> list[Callable | str]: ... -def flatten_fieldsets(fieldsets: Any) -> list[Callable | str]: ... +def flatten(fields: Any) -> list[Callable[..., Any] | str]: ... +def flatten_fieldsets(fieldsets: Any) -> list[Callable[..., Any] | str]: ... def get_deleted_objects( objs: Sequence[Model | None] | QuerySet[Model], request: HttpRequest, admin_site: AdminSite ) -> tuple[list[Model], dict[str, int], set[str], list[str]]: ... @@ -41,9 +41,9 @@ class NestedObjects(Collector): def __init__(self, *args: Any, **kwargs: Any) -> None: ... def add_edge(self, source: Model | None, target: Model) -> None: ... def related_objects( - self, related_model: type[Model], related_fields: Iterable[Field], objs: _IndexableCollection[Model] + self, related_model: type[Model], related_fields: Iterable[Field[Any, Any]], objs: _IndexableCollection[Model] ) -> QuerySet[Model]: ... - def nested(self, format_callback: Callable = ...) -> list[Any]: ... + def nested(self, format_callback: Callable[..., Any] = ...) -> list[Any]: ... def can_fast_delete(self, *args: Any, **kwargs: Any) -> bool: ... class _ModelFormatDict(TypedDict): @@ -53,33 +53,33 @@ class _ModelFormatDict(TypedDict): def model_format_dict(obj: Model | type[Model] | QuerySet | Options[Model]) -> _ModelFormatDict: ... def model_ngettext(obj: Options | QuerySet, n: int | None = ...) -> str: ... def lookup_field( - name: Callable | str, obj: Model, model_admin: BaseModelAdmin | None = ... -) -> tuple[Field | None, str | None, Any]: ... + name: Callable[..., Any] | str, obj: Model, model_admin: BaseModelAdmin | None = ... +) -> tuple[Field[Any, Any] | None, str | None, Any]: ... @overload def label_for_field( # type: ignore - name: Callable | str, + name: Callable[..., Any] | str, model: type[Model], model_admin: BaseModelAdmin | None = ..., return_attr: Literal[True] = ..., form: BaseForm | None = ..., -) -> tuple[str, Callable | str | None]: ... +) -> tuple[str, Callable[..., Any] | str | None]: ... @overload def label_for_field( - name: Callable | str, + name: Callable[..., Any] | str, model: type[Model], model_admin: BaseModelAdmin | None = ..., return_attr: Literal[False] = ..., form: BaseForm | None = ..., ) -> str: ... def help_text_for_field(name: str, model: type[Model]) -> str: ... -def display_for_field(value: Any, field: Field, empty_value_display: str) -> str: ... +def display_for_field(value: Any, field: Field[Any, Any], empty_value_display: str) -> str: ... def display_for_value(value: Any, empty_value_display: str, boolean: bool = ...) -> str: ... class NotRelationField(Exception): ... -def get_model_from_relation(field: Field | reverse_related.ForeignObjectRel) -> type[Model]: ... +def get_model_from_relation(field: Field[Any, Any] | reverse_related.ForeignObjectRel) -> type[Model]: ... def reverse_field_path(model: type[Model], path: str) -> tuple[type[Model], str]: ... -def get_fields_from_path(model: type[Model], path: str) -> list[Field]: ... +def get_fields_from_path(model: type[Model], path: str) -> list[Field[Any, Any]]: ... def construct_change_message( form: AdminPasswordChangeForm, formsets: Iterable[BaseFormSet], add: bool ) -> list[dict[str, dict[str, list[str]]]]: ... diff --git a/django-stubs/contrib/admin/views/decorators.pyi b/django-stubs/contrib/admin/views/decorators.pyi index 6a6a6c23a..2f9a5c6a1 100644 --- a/django-stubs/contrib/admin/views/decorators.pyi +++ b/django-stubs/contrib/admin/views/decorators.pyi @@ -1,11 +1,11 @@ from collections.abc import Callable -from typing import TypeVar, overload +from typing import Any, TypeVar, overload -_C = TypeVar("_C", bound=Callable) +_C = TypeVar("_C", bound=Callable[..., Any]) @overload def staff_member_required(view_func: _C = ..., redirect_field_name: str | None = ..., login_url: str = ...) -> _C: ... @overload def staff_member_required( view_func: None = ..., redirect_field_name: str | None = ..., login_url: str = ... -) -> Callable: ... +) -> Callable[..., Any]: ... diff --git a/django-stubs/contrib/admin/views/main.pyi b/django-stubs/contrib/admin/views/main.pyi index 231788ddf..fcc2a0417 100644 --- a/django-stubs/contrib/admin/views/main.pyi +++ b/django-stubs/contrib/admin/views/main.pyi @@ -76,7 +76,7 @@ class ChangeList: multi_page: bool paginator: Any def get_results(self, request: HttpRequest) -> None: ... - def get_ordering_field(self, field_name: Callable | str) -> Expression | str | None: ... + def get_ordering_field(self, field_name: Callable[..., Any] | str) -> Expression | str | None: ... def get_ordering(self, request: HttpRequest, queryset: QuerySet) -> list[Expression | str]: ... def get_ordering_field_columns(self) -> dict[int, Literal["desc", "asc"]]: ... def get_queryset(self, request: HttpRequest) -> QuerySet: ... diff --git a/django-stubs/contrib/admindocs/utils.pyi b/django-stubs/contrib/admindocs/utils.pyi index 9c7f5d2fb..8394bf372 100644 --- a/django-stubs/contrib/admindocs/utils.pyi +++ b/django-stubs/contrib/admindocs/utils.pyi @@ -5,7 +5,7 @@ from django.utils.safestring import SafeString docutils_is_available: bool -def get_view_name(view_func: Callable) -> str: ... +def get_view_name(view_func: Callable[..., Any]) -> str: ... def parse_docstring(docstring: str) -> tuple[str, str, dict[str, str]]: ... def parse_rst(text: str, default_reference_context: Any, thing_being_parsed: Any | None = ...) -> SafeString: ... diff --git a/django-stubs/contrib/admindocs/views.pyi b/django-stubs/contrib/admindocs/views.pyi index 0c19bb5d7..6fc517d9b 100644 --- a/django-stubs/contrib/admindocs/views.pyi +++ b/django-stubs/contrib/admindocs/views.pyi @@ -19,8 +19,8 @@ class ModelDetailView(BaseAdminDocsView): ... class TemplateDetailView(BaseAdminDocsView): ... def get_return_data_type(func_name: Any) -> str: ... -def get_readable_field_data_type(field: Field | str) -> str: ... +def get_readable_field_data_type(field: Field[Any, Any] | str) -> str: ... def extract_views_from_urlpatterns( urlpatterns: Iterable[_AnyURL], base: str = ..., namespace: str | None = ... -) -> list[tuple[Callable, Pattern[str], str | None, str | None]]: ... +) -> list[tuple[Callable[..., Any], Pattern[str], str | None, str | None]]: ... def simplify_regex(pattern: str) -> str: ... diff --git a/django-stubs/contrib/auth/forms.pyi b/django-stubs/contrib/auth/forms.pyi index f6f3edfbb..c3a1d5b11 100644 --- a/django-stubs/contrib/auth/forms.pyi +++ b/django-stubs/contrib/auth/forms.pyi @@ -45,7 +45,7 @@ class AuthenticationForm(forms.Form): error_messages: _ErrorMessagesT request: HttpRequest | None user_cache: Any - username_field: models.Field + username_field: models.Field[Any, Any] def __init__(self, request: HttpRequest | None = ..., *args: Any, **kwargs: Any) -> None: ... def confirm_login_allowed(self, user: AbstractBaseUser) -> None: ... def get_user(self) -> AbstractBaseUser: ... diff --git a/django-stubs/contrib/auth/hashers.pyi b/django-stubs/contrib/auth/hashers.pyi index b1eba698f..5bbe8c398 100644 --- a/django-stubs/contrib/auth/hashers.pyi +++ b/django-stubs/contrib/auth/hashers.pyi @@ -5,7 +5,9 @@ UNUSABLE_PASSWORD_PREFIX: str UNUSABLE_PASSWORD_SUFFIX_LENGTH: int def is_password_usable(encoded: str | None) -> bool: ... -def check_password(password: str | None, encoded: str, setter: Callable | None = ..., preferred: str = ...) -> bool: ... +def check_password( + password: str | None, encoded: str, setter: Callable[..., Any] | None = ..., preferred: str = ... +) -> bool: ... def make_password(password: str | None, salt: str | None = ..., hasher: str | BasePasswordHasher = ...) -> str: ... def get_hashers() -> list[BasePasswordHasher]: ... def get_hashers_by_algorithm() -> dict[str, BasePasswordHasher]: ... diff --git a/django-stubs/contrib/auth/mixins.pyi b/django-stubs/contrib/auth/mixins.pyi index d344dfa5c..c3a23a661 100644 --- a/django-stubs/contrib/auth/mixins.pyi +++ b/django-stubs/contrib/auth/mixins.pyi @@ -26,5 +26,5 @@ class PermissionRequiredMixin(AccessMixin): class UserPassesTestMixin(AccessMixin): def test_func(self) -> bool | None: ... - def get_test_func(self) -> Callable: ... + def get_test_func(self) -> Callable[..., Any]: ... def dispatch(self, request: http.HttpRequest, *args: Any, **kwargs: Any) -> HttpResponseBase: ... diff --git a/django-stubs/contrib/contenttypes/fields.pyi b/django-stubs/contrib/contenttypes/fields.pyi index f1c5b9118..19783ecc1 100644 --- a/django-stubs/contrib/contenttypes/fields.pyi +++ b/django-stubs/contrib/contenttypes/fields.pyi @@ -48,7 +48,7 @@ class GenericForeignKey(FieldCacheMixin): ) -> ContentType: ... def get_prefetch_queryset( self, instances: list[Model] | QuerySet, queryset: QuerySet | None = ... - ) -> tuple[list[Model], Callable, Callable, bool, str, bool]: ... + ) -> tuple[list[Model], Callable[..., Any], Callable[..., Any], bool, str, bool]: ... def __get__(self, instance: Model | None, cls: type[Model] | None = ...) -> Any | None: ... def __set__(self, instance: Model, value: Any | None) -> None: ... @@ -80,7 +80,7 @@ class GenericRelation(ForeignObject): limit_choices_to: dict[str, Any] | Callable[[], Any] | None = ..., **kwargs: Any ) -> None: ... - def resolve_related_fields(self) -> list[tuple[Field, Field]]: ... + def resolve_related_fields(self) -> list[tuple[Field[Any, Any], Field[Any, Any]]]: ... def get_path_info(self, filtered_relation: FilteredRelation | None = ...) -> list[PathInfo]: ... def get_reverse_path_info(self, filtered_relation: FilteredRelation | None = ...) -> list[PathInfo]: ... def get_content_type(self) -> ContentType: ... diff --git a/django-stubs/contrib/gis/db/models/fields.pyi b/django-stubs/contrib/gis/db/models/fields.pyi index 98e55f9d0..df7a5de3f 100644 --- a/django-stubs/contrib/gis/db/models/fields.pyi +++ b/django-stubs/contrib/gis/db/models/fields.pyi @@ -30,7 +30,7 @@ class SRIDCacheEntry(NamedTuple): def get_srid_info(srid: int, connection: Any) -> SRIDCacheEntry: ... class BaseSpatialField(Field[_ST, _GT]): - form_class: type[forms.GeometryField] + form_class: type[forms.GeometryField[Any, Any]] geom_type: str geom_class: type[GEOSGeometry] | None geography: bool @@ -114,33 +114,33 @@ class GeometryField(BaseSpatialField): class PointField(GeometryField): geom_class: type[Point] - form_class: type[forms.PointField] + form_class: type[forms.PointField[Any, Any]] class LineStringField(GeometryField): geom_class: type[LineString] - form_class: type[forms.LineStringField] + form_class: type[forms.LineStringField[Any, Any]] class PolygonField(GeometryField): geom_class: type[Polygon] - form_class: type[forms.PolygonField] + form_class: type[forms.PolygonField[Any, Any]] class MultiPointField(GeometryField): geom_class: type[MultiPoint] - form_class: type[forms.MultiPointField] + form_class: type[forms.MultiPointField[Any, Any]] class MultiLineStringField(GeometryField): geom_class: type[MultiLineString] - form_class: type[forms.MultiLineStringField] + form_class: type[forms.MultiLineStringField[Any, Any]] class MultiPolygonField(GeometryField): geom_class: type[MultiPolygon] - form_class: type[forms.MultiPolygonField] + form_class: type[forms.MultiPolygonField[Any, Any]] class GeometryCollectionField(GeometryField): geom_class: type[GeometryCollection] - form_class: type[forms.GeometryCollectionField] + form_class: type[forms.GeometryCollectionField[Any, Any]] -class ExtentField(Field): +class ExtentField(Field[Any, Any]): def get_internal_type(self) -> Any: ... def select_format(self, compiler: Any, sql: Any, params: Any) -> Any: ... diff --git a/django-stubs/contrib/gis/utils/layermapping.pyi b/django-stubs/contrib/gis/utils/layermapping.pyi index ad0cbb92b..dbd45392b 100644 --- a/django-stubs/contrib/gis/utils/layermapping.pyi +++ b/django-stubs/contrib/gis/utils/layermapping.pyi @@ -19,7 +19,7 @@ class _Writer(Protocol): class LayerMapping: MULTI_TYPES: dict[int, OGRGeomType] - FIELD_TYPES: dict[Field, OGRField | tuple[OGRField, ...]] + FIELD_TYPES: dict[Field[Any, Any], OGRField | tuple[OGRField, ...]] ds: DataSource layer: Layer using: str @@ -48,7 +48,7 @@ class LayerMapping: ) -> None: ... def check_fid_range(self, fid_range: Any) -> Any: ... geom_field: str - fields: dict[str, Field] + fields: dict[str, Field[Any, Any]] coord_dim: int def check_layer(self) -> Any: ... def check_srs(self, source_srs: Any) -> Any: ... diff --git a/django-stubs/contrib/humanize/templatetags/humanize.pyi b/django-stubs/contrib/humanize/templatetags/humanize.pyi index 0bc6e2997..4536676a6 100644 --- a/django-stubs/contrib/humanize/templatetags/humanize.pyi +++ b/django-stubs/contrib/humanize/templatetags/humanize.pyi @@ -10,7 +10,7 @@ register: template.Library def ordinal(value: str | SupportsInt | None) -> str | None: ... def intcomma(value: str | SupportsInt | None, use_l10n: bool = ...) -> str: ... -intword_converters: tuple[tuple[int, Callable]] +intword_converters: tuple[tuple[int, Callable[..., Any]]] def intword(value: str | SupportsInt | None) -> int | str | None: ... def apnumber(value: str | SupportsInt | None) -> int | str | None: ... diff --git a/django-stubs/contrib/postgres/fields/array.pyi b/django-stubs/contrib/postgres/fields/array.pyi index 0eabe5105..7c538f944 100644 --- a/django-stubs/contrib/postgres/fields/array.pyi +++ b/django-stubs/contrib/postgres/fields/array.pyi @@ -19,13 +19,13 @@ class ArrayField(CheckFieldDefaultMixin, Field[_ST, _GT]): empty_strings_allowed: bool default_error_messages: _ErrorMessagesT - base_field: Field + base_field: Field[Any, Any] size: int | None default_validators: Sequence[_ValidatorCallable] from_db_value: Any def __init__( self, - base_field: Field, + base_field: Field[Any, Any], size: int | None = ..., *, verbose_name: _StrOrPromise | None = ..., diff --git a/django-stubs/contrib/postgres/fields/hstore.pyi b/django-stubs/contrib/postgres/fields/hstore.pyi index 207f79037..ad57700ee 100644 --- a/django-stubs/contrib/postgres/fields/hstore.pyi +++ b/django-stubs/contrib/postgres/fields/hstore.pyi @@ -3,7 +3,7 @@ from typing import Any from django.db.models import Field, Transform from django.db.models.fields.mixins import CheckFieldDefaultMixin -class HStoreField(CheckFieldDefaultMixin, Field): +class HStoreField(CheckFieldDefaultMixin, Field[Any, Any]): def get_transform(self, name: str) -> Any: ... class KeyTransform(Transform): diff --git a/django-stubs/contrib/postgres/fields/ranges.pyi b/django-stubs/contrib/postgres/fields/ranges.pyi index a8259ce9f..53b95fe6a 100644 --- a/django-stubs/contrib/postgres/fields/ranges.pyi +++ b/django-stubs/contrib/postgres/fields/ranges.pyi @@ -22,9 +22,9 @@ class RangeOperators: NOT_GT: Literal["&<"] ADJACENT_TO: Literal["-|-"] -class RangeField(models.Field): +class RangeField(models.Field[Any, Any]): empty_strings_allowed: bool - base_field: models.Field + base_field: models.Field[Any, Any] range_type: type[Range] def get_prep_value(self, value: Any) -> Any | None: ... def to_python(self, value: Any) -> Any: ... @@ -77,13 +77,13 @@ class RangeStartsWith(models.Transform): lookup_name: str function: str @property - def output_field(self) -> models.Field: ... + def output_field(self) -> models.Field[Any, Any]: ... class RangeEndsWith(models.Transform): lookup_name: str function: str @property - def output_field(self) -> models.Field: ... + def output_field(self) -> models.Field[Any, Any]: ... class IsEmpty(models.Transform): lookup_name: str diff --git a/django-stubs/contrib/postgres/search.pyi b/django-stubs/contrib/postgres/search.pyi index 48a91f213..2746caa96 100644 --- a/django-stubs/contrib/postgres/search.pyi +++ b/django-stubs/contrib/postgres/search.pyi @@ -9,8 +9,8 @@ from typing_extensions import TypeAlias _Expression: TypeAlias = str | Combinable | SearchQueryCombinable class SearchVectorExact(Lookup): ... -class SearchVectorField(Field): ... -class SearchQueryField(Field): ... +class SearchVectorField(Field[Any, Any]): ... +class SearchQueryField(Field[Any, Any]): ... class SearchConfig(Expression): config: _Expression | None @@ -25,7 +25,7 @@ class SearchVector(SearchVectorCombinable, Func): config: _Expression | None function: str arg_joiner: str - output_field: Field + output_field: Field[Any, Any] def __init__( self, *expressions: _Expression, config: _Expression | None = ..., weight: Any | None = ... ) -> None: ... @@ -37,7 +37,7 @@ class CombinedSearchVector(SearchVectorCombinable, CombinedExpression): connector: str, rhs: Combinable, config: _Expression | None, - output_field: Field | None = ..., + output_field: Field[Any, Any] | None = ..., ) -> None: ... class SearchQueryCombinable: @@ -53,7 +53,7 @@ class SearchQuery(SearchQueryCombinable, Func): # type: ignore def __init__( self, value: _Expression, - output_field: Field | None = ..., + output_field: Field[Any, Any] | None = ..., *, config: _Expression | None = ..., invert: bool = ..., @@ -68,7 +68,7 @@ class CombinedSearchQuery(SearchQueryCombinable, CombinedExpression): # type: i connector: str, rhs: Combinable, config: _Expression | None, - output_field: Field | None = ..., + output_field: Field[Any, Any] | None = ..., ) -> None: ... class SearchRank(Func): @@ -84,7 +84,7 @@ class SearchRank(Func): class SearchHeadline(Func): function: str template: str - output_field: Field + output_field: Field[Any, Any] def __init__( self, expression: _Expression, diff --git a/django-stubs/contrib/sitemaps/views.pyi b/django-stubs/contrib/sitemaps/views.pyi index 9ba674d53..e36b9dc55 100644 --- a/django-stubs/contrib/sitemaps/views.pyi +++ b/django-stubs/contrib/sitemaps/views.pyi @@ -1,11 +1,11 @@ from collections.abc import Callable -from typing import TypeVar +from typing import Any, TypeVar from django.contrib.sitemaps import GenericSitemap, Sitemap from django.http.request import HttpRequest from django.template.response import TemplateResponse -_C = TypeVar("_C", bound=Callable) +_C = TypeVar("_C", bound=Callable[..., Any]) def x_robots_tag(func: _C) -> _C: ... def index( diff --git a/django-stubs/contrib/staticfiles/storage.pyi b/django-stubs/contrib/staticfiles/storage.pyi index 0098153f9..ad294d211 100644 --- a/django-stubs/contrib/staticfiles/storage.pyi +++ b/django-stubs/contrib/staticfiles/storage.pyi @@ -27,7 +27,7 @@ class HashedFilesMixin: def file_hash(self, name: str, content: File = ...) -> str: ... def hashed_name(self, name: str, content: File | None = ..., filename: str | None = ...) -> str: ... def url(self, name: str, force: bool = ...) -> str: ... - def url_converter(self, name: str, hashed_files: dict[str, Any], template: str = ...) -> Callable: ... + def url_converter(self, name: str, hashed_files: dict[str, Any], template: str = ...) -> Callable[..., Any]: ... def post_process(self, paths: dict[str, Any], dry_run: bool = ..., **options: Any) -> _PostProcessT: ... def clean_name(self, name: str) -> str: ... def hash_key(self, name: str) -> str: ... diff --git a/django-stubs/core/cache/backends/base.pyi b/django-stubs/core/cache/backends/base.pyi index 1e64f7863..0febb8514 100644 --- a/django-stubs/core/cache/backends/base.pyi +++ b/django-stubs/core/cache/backends/base.pyi @@ -11,7 +11,7 @@ DEFAULT_TIMEOUT: Any MEMCACHE_MAX_KEY_LENGTH: int def default_key_func(key: Any, key_prefix: str, version: Any) -> str: ... -def get_key_func(key_func: Callable | str | None) -> Callable: ... +def get_key_func(key_func: Callable[..., Any] | str | None) -> Callable[..., Any]: ... class BaseCache: _missing_key: object @@ -20,7 +20,7 @@ class BaseCache: _cull_frequency: int key_prefix: str version: int - key_func: Callable + key_func: Callable[..., Any] def __init__(self, params: dict[str, Any]) -> None: ... def get_backend_timeout(self, timeout: float | None = ...) -> float | None: ... def make_key(self, key: Any, version: int | None = ...) -> str: ... diff --git a/django-stubs/core/management/base.pyi b/django-stubs/core/management/base.pyi index cbd4bc53c..5c90e56de 100644 --- a/django-stubs/core/management/base.pyi +++ b/django-stubs/core/management/base.pyi @@ -22,7 +22,7 @@ class CommandParser(ArgumentParser): def error(self, message: str) -> Any: ... def handle_default_options(options: Namespace) -> None: ... -def no_translations(handle_func: Callable) -> Callable: ... +def no_translations(handle_func: Callable[..., Any]) -> Callable[..., Any]: ... class DjangoHelpFormatter(HelpFormatter): show_last: set[str] @@ -36,7 +36,7 @@ class OutputWrapper(TextIOBase): def style_func(self, style_func: Callable[[str], str] | None) -> None: ... ending: str def __init__(self, out: TextIO, ending: str = ...) -> None: ... - def __getattr__(self, name: str) -> Callable: ... + def __getattr__(self, name: str) -> Callable[..., Any]: ... def flush(self) -> None: ... def isatty(self) -> bool: ... def write( # type: ignore[override] diff --git a/django-stubs/core/serializers/__init__.pyi b/django-stubs/core/serializers/__init__.pyi index 2349d006b..dd357d2ba 100644 --- a/django-stubs/core/serializers/__init__.pyi +++ b/django-stubs/core/serializers/__init__.pyi @@ -24,7 +24,7 @@ def unregister_serializer(format: str) -> None: ... def get_serializer(format: str) -> type[Serializer] | BadSerializer: ... def get_serializer_formats() -> list[str]: ... def get_public_serializer_formats() -> list[str]: ... -def get_deserializer(format: str) -> Callable | type[Deserializer]: ... +def get_deserializer(format: str) -> Callable[..., Any] | type[Deserializer]: ... def serialize(format: str, queryset: Iterable[Model], **options: Any) -> Any: ... def deserialize(format: str, stream_or_string: Any, **options: Any) -> Iterator[DeserializedObject]: ... def sort_dependencies(app_list: Iterable[Any], allow_cycles: bool = ...) -> list[type[Model]]: ... diff --git a/django-stubs/core/serializers/base.pyi b/django-stubs/core/serializers/base.pyi index b1d2be05a..5931ca35e 100644 --- a/django-stubs/core/serializers/base.pyi +++ b/django-stubs/core/serializers/base.pyi @@ -70,12 +70,12 @@ class Deserializer: class DeserializedObject: object: Any m2m_data: dict[str, Sequence[Any]] | None - deferred_fields: dict[Field, Any] + deferred_fields: dict[Field[Any, Any], Any] def __init__( self, obj: Model, m2m_data: dict[str, Sequence[Any]] | None = ..., - deferred_fields: dict[Field, Any] | None = ..., + deferred_fields: dict[Field[Any, Any], Any] | None = ..., ) -> None: ... def save(self, save_m2m: bool = ..., using: str | None = ..., **kwargs: Any) -> None: ... def save_deferred_fields(self, using: str | None = ...) -> None: ... diff --git a/django-stubs/core/serializers/pyyaml.pyi b/django-stubs/core/serializers/pyyaml.pyi index d6a439850..b0cfb10d6 100644 --- a/django-stubs/core/serializers/pyyaml.pyi +++ b/django-stubs/core/serializers/pyyaml.pyi @@ -13,7 +13,7 @@ class DjangoSafeDumper(SafeDumper): class Serializer(PythonSerializer): internal_use_only: bool - def handle_field(self, obj: Any, field: Field) -> None: ... + def handle_field(self, obj: Any, field: Field[Any, Any]) -> None: ... def end_serialization(self) -> None: ... def getvalue(self) -> Any: ... diff --git a/django-stubs/db/backends/base/operations.pyi b/django-stubs/db/backends/base/operations.pyi index 040fc8e37..755ecb94e 100644 --- a/django-stubs/db/backends/base/operations.pyi +++ b/django-stubs/db/backends/base/operations.pyi @@ -30,7 +30,7 @@ class BaseDatabaseOperations: def autoinc_sql(self, table: str, column: str) -> str | None: ... def bulk_batch_size(self, fields: Any, objs: Any) -> int: ... def cache_key_culling_sql(self) -> str: ... - def unification_cast_sql(self, output_field: Field) -> str: ... + def unification_cast_sql(self, output_field: Field[Any, Any]) -> str: ... def date_extract_sql(self, lookup_type: str, field_name: str) -> Any: ... # def date_interval_sql(self, timedelta: None) -> Any: ... def date_trunc_sql(self, lookup_type: str, field_name: str, tzname: str | None = ...) -> str: ... diff --git a/django-stubs/db/backends/base/schema.pyi b/django-stubs/db/backends/base/schema.pyi index 324d1c34d..3aa596530 100644 --- a/django-stubs/db/backends/base/schema.pyi +++ b/django-stubs/db/backends/base/schema.pyi @@ -61,11 +61,11 @@ class BaseDatabaseSchemaEditor(AbstractContextManager[Any]): def quote_name(self, name: str) -> str: ... def table_sql(self, model: type[Model]) -> tuple[str, list[Any]]: ... def column_sql( - self, model: type[Model], field: Field, include_default: bool = ... + self, model: type[Model], field: Field[Any, Any], include_default: bool = ... ) -> tuple[None, None] | tuple[str, list[Any]]: ... def skip_default(self, field: Any) -> bool: ... def prepare_default(self, value: Any) -> Any: ... - def effective_default(self, field: Field) -> int | str: ... + def effective_default(self, field: Field[Any, Any]) -> int | str: ... def quote_value(self, value: Any) -> str: ... def create_model(self, model: type[Model]) -> None: ... def delete_model(self, model: type[Model]) -> None: ... @@ -87,5 +87,7 @@ class BaseDatabaseSchemaEditor(AbstractContextManager[Any]): 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_field(self, model: type[Model], old_field: Field, new_field: Field, strict: bool = ...) -> None: ... + def alter_field( + self, model: type[Model], old_field: Field[Any, Any], new_field: Field[Any, Any], strict: bool = ... + ) -> None: ... def remove_procedure(self, procedure_name: Any, param_types: Any = ...) -> None: ... diff --git a/django-stubs/db/backends/base/validation.pyi b/django-stubs/db/backends/base/validation.pyi index 6d1c8acb3..94a8d4c10 100644 --- a/django-stubs/db/backends/base/validation.pyi +++ b/django-stubs/db/backends/base/validation.pyi @@ -7,4 +7,4 @@ class BaseDatabaseValidation: connection: BaseDatabaseWrapper def __init__(self, connection: BaseDatabaseWrapper) -> None: ... def check(self, **kwargs: Any) -> list[Any]: ... - def check_field(self, field: Field, **kwargs: Any) -> list[Any]: ... + def check_field(self, field: Field[Any, Any], **kwargs: Any) -> list[Any]: ... diff --git a/django-stubs/db/migrations/autodetector.pyi b/django-stubs/db/migrations/autodetector.pyi index 931945734..2b92be174 100644 --- a/django-stubs/db/migrations/autodetector.pyi +++ b/django-stubs/db/migrations/autodetector.pyi @@ -25,8 +25,8 @@ class MigrationAutodetector: ) -> dict[str, list[Migration]]: ... def deep_deconstruct(self, obj: Any) -> Any: ... def only_relation_agnostic_fields( - self, fields: dict[str, Field] - ) -> list[tuple[str, list[Any], dict[str, Callable | int | str]]]: ... + self, fields: dict[str, Field[Any, Any]] + ) -> list[tuple[str, list[Any], dict[str, Callable[..., Any] | int | str]]]: ... def check_dependency(self, operation: Operation, dependency: tuple[str, str, str | None, bool | str]) -> bool: ... def add_operation( self, diff --git a/django-stubs/db/migrations/operations/fields.pyi b/django-stubs/db/migrations/operations/fields.pyi index ea55695d5..52d70e20d 100644 --- a/django-stubs/db/migrations/operations/fields.pyi +++ b/django-stubs/db/migrations/operations/fields.pyi @@ -1,3 +1,5 @@ +from typing import Any + from django.db.models.fields import Field from .base import Operation @@ -5,7 +7,7 @@ from .base import Operation class FieldOperation(Operation): model_name: str name: str - def __init__(self, model_name: str, name: str, field: Field | None = ...) -> None: ... + def __init__(self, model_name: str, name: str, field: Field[Any, Any] | None = ...) -> None: ... @property def name_lower(self) -> str: ... @property @@ -14,16 +16,16 @@ class FieldOperation(Operation): def is_same_field_operation(self, operation: FieldOperation) -> bool: ... class AddField(FieldOperation): - field: Field + field: Field[Any, Any] preserve_default: bool - def __init__(self, model_name: str, name: str, field: Field, preserve_default: bool = ...) -> None: ... + def __init__(self, model_name: str, name: str, field: Field[Any, Any], preserve_default: bool = ...) -> None: ... class RemoveField(FieldOperation): ... class AlterField(FieldOperation): - field: Field + field: Field[Any, Any] preserve_default: bool - def __init__(self, model_name: str, name: str, field: Field, preserve_default: bool = ...) -> None: ... + def __init__(self, model_name: str, name: str, field: Field[Any, Any], preserve_default: bool = ...) -> None: ... class RenameField(FieldOperation): old_name: str diff --git a/django-stubs/db/migrations/operations/models.pyi b/django-stubs/db/migrations/operations/models.pyi index 35e65b7b4..3809ac3be 100644 --- a/django-stubs/db/migrations/operations/models.pyi +++ b/django-stubs/db/migrations/operations/models.pyi @@ -17,14 +17,14 @@ class ModelOperation(Operation): def name_lower(self) -> str: ... class CreateModel(ModelOperation): - fields: list[tuple[str, Field]] + fields: list[tuple[str, Field[Any, Any]]] options: dict[str, Any] bases: Sequence[type[Model] | str] | None managers: Sequence[tuple[str, Manager]] | None def __init__( self, name: str, - fields: list[tuple[str, Field]], + fields: list[tuple[str, Field[Any, Any]]], options: dict[str, Any] | None = ..., bases: Sequence[type[Model] | str] | None = ..., managers: Sequence[tuple[str, Manager]] | None = ..., diff --git a/django-stubs/db/migrations/operations/special.pyi b/django-stubs/db/migrations/operations/special.pyi index 7698068d4..06c98302c 100644 --- a/django-stubs/db/migrations/operations/special.pyi +++ b/django-stubs/db/migrations/operations/special.pyi @@ -35,12 +35,12 @@ class _CodeCallable(Protocol): class RunPython(Operation): code: _CodeCallable - reverse_code: _CodeCallable | None + reverse_code: _CodeCallable[..., Any] | None hints: Mapping[str, Any] def __init__( self, code: _CodeCallable, - reverse_code: _CodeCallable | None = ..., + reverse_code: _CodeCallable[..., Any] | None = ..., atomic: bool | None = ..., hints: Mapping[str, Any] | None = ..., elidable: bool = ..., diff --git a/django-stubs/db/migrations/operations/utils.pyi b/django-stubs/db/migrations/operations/utils.pyi index 8fd2c2cd0..62af5b921 100644 --- a/django-stubs/db/migrations/operations/utils.pyi +++ b/django-stubs/db/migrations/operations/utils.pyi @@ -1,5 +1,6 @@ from collections import namedtuple from collections.abc import Iterator +from typing import Any from django.db.migrations.state import ModelState, ProjectState from django.db.models import Field, Model @@ -13,14 +14,16 @@ FieldReference = namedtuple("FieldReference", ["to", "through"]) def field_references( model_tuple: tuple[str, str], - field: Field, + field: Field[Any, Any], reference_model_tuple: tuple[str, str], reference_field_name: str | None = ..., - reference_field: Field | None = ..., + reference_field: Field[Any, Any] | None = ..., ) -> Literal[False] | FieldReference: ... def get_references( state: ProjectState, model_tuple: tuple[str, str], - field_tuple: tuple[()] | tuple[str, Field] = ..., -) -> Iterator[tuple[ModelState, str, Field, FieldReference]]: ... -def field_is_referenced(state: ProjectState, model_tuple: tuple[str, str], field_tuple: tuple[str, Field]) -> bool: ... + field_tuple: tuple[()] | tuple[str, Field[Any, Any]] = ..., +) -> Iterator[tuple[ModelState, str, Field[Any, Any], FieldReference]]: ... +def field_is_referenced( + state: ProjectState, model_tuple: tuple[str, str], field_tuple: tuple[str, Field[Any, Any]] +) -> bool: ... diff --git a/django-stubs/db/migrations/questioner.pyi b/django-stubs/db/migrations/questioner.pyi index 542cd2ac6..b212a27a9 100644 --- a/django-stubs/db/migrations/questioner.pyi +++ b/django-stubs/db/migrations/questioner.pyi @@ -16,7 +16,7 @@ class MigrationQuestioner: def ask_initial(self, app_label: str) -> bool: ... def ask_not_null_addition(self, field_name: str, model_name: str) -> Any: ... def ask_not_null_alteration(self, field_name: Any, model_name: Any) -> Any: ... - def ask_rename(self, model_name: str, old_name: str, new_name: str, field_instance: Field) -> bool: ... + def ask_rename(self, model_name: str, old_name: str, new_name: str, field_instance: Field[Any, Any]) -> bool: ... def ask_rename_model(self, old_model_state: ModelState, new_model_state: ModelState) -> bool: ... def ask_merge(self, app_label: str) -> bool: ... def ask_auto_now_add_addition(self, field_name: str, model_name: str) -> Any: ... diff --git a/django-stubs/db/migrations/serializer.pyi b/django-stubs/db/migrations/serializer.pyi index c20167b76..fd14d78f2 100644 --- a/django-stubs/db/migrations/serializer.pyi +++ b/django-stubs/db/migrations/serializer.pyi @@ -15,7 +15,7 @@ class DecimalSerializer(BaseSerializer): ... class DeconstructableSerializer(BaseSerializer): @staticmethod def serialize_deconstructed( - path: str, args: list[Any], kwargs: dict[str, Callable | int | str] + path: str, args: list[Any], kwargs: dict[str, Callable[..., Any] | int | str] ) -> tuple[str, set[str]]: ... class DictionarySerializer(BaseSerializer): ... diff --git a/django-stubs/db/migrations/state.pyi b/django-stubs/db/migrations/state.pyi index e09472879..f09dad798 100644 --- a/django-stubs/db/migrations/state.pyi +++ b/django-stubs/db/migrations/state.pyi @@ -13,7 +13,7 @@ class AppConfigStub(AppConfig): ... class ModelState: name: str app_label: str - fields: dict[str, Field] + fields: dict[str, Field[Any, Any]] options: dict[str, Any] bases: Sequence[type[Model] | str] managers: list[tuple[str, Manager]] @@ -21,7 +21,7 @@ class ModelState: self, app_label: str, name: str, - fields: list[tuple[str, Field]] | dict[str, Field], + fields: list[tuple[str, Field[Any, Any]]] | dict[str, Field[Any, Any]], options: dict[str, Any] | None = ..., bases: Sequence[type[Model] | str] | None = ..., managers: list[tuple[str, Manager]] | None = ..., diff --git a/django-stubs/db/models/deletion.pyi b/django-stubs/db/models/deletion.pyi index 7b688a61c..700b353eb 100644 --- a/django-stubs/db/models/deletion.pyi +++ b/django-stubs/db/models/deletion.pyi @@ -45,7 +45,7 @@ def RESTRICT( using: str, ) -> None: ... def SET(value: Any) -> Callable[..., Any]: ... -def get_candidate_relations_to_delete(opts: Options) -> Iterable[Field]: ... +def get_candidate_relations_to_delete(opts: Options) -> Iterable[Field[Any, Any]]: ... class ProtectedError(IntegrityError): protected_objects: set[Model] @@ -71,13 +71,13 @@ class Collector: reverse_dependency: bool = ..., ) -> list[Model]: ... def add_dependency(self, model: type[Model], dependency: type[Model], reverse_dependency: bool = ...) -> None: ... - def add_field_update(self, field: Field, value: Any, objs: _IndexableCollection[Model]) -> None: ... - def add_restricted_objects(self, field: Field, objs: _IndexableCollection[Model]) -> None: ... + def add_field_update(self, field: Field[Any, Any], value: Any, objs: _IndexableCollection[Model]) -> None: ... + def add_restricted_objects(self, field: Field[Any, Any], objs: _IndexableCollection[Model]) -> None: ... def clear_restricted_objects_from_set(self, model: type[Model], objs: set[Model]) -> None: ... def clear_restricted_objects_from_queryset(self, model: type[Model], qs: QuerySet[Model]) -> None: ... - def can_fast_delete(self, objs: Model | Iterable[Model], from_field: Field | None = ...) -> bool: ... + def can_fast_delete(self, objs: Model | Iterable[Model], from_field: Field[Any, Any] | None = ...) -> bool: ... def get_del_batches( - self, objs: _IndexableCollection[Model], fields: Iterable[Field] + self, objs: _IndexableCollection[Model], fields: Iterable[Field[Any, Any]] ) -> Sequence[Sequence[Model]]: ... def collect( self, @@ -91,7 +91,7 @@ class Collector: fail_on_restricted: bool = ..., ) -> None: ... def related_objects( - self, related_model: type[Model], related_fields: Iterable[Field], objs: _IndexableCollection[Model] + self, related_model: type[Model], related_fields: Iterable[Field[Any, Any]], objs: _IndexableCollection[Model] ) -> QuerySet[Model]: ... def instances_with_model(self) -> Iterator[tuple[type[Model], Model]]: ... def sort(self) -> None: ... diff --git a/django-stubs/db/models/expressions.pyi b/django-stubs/db/models/expressions.pyi index b2be3de0f..cfe4ac83d 100644 --- a/django-stubs/db/models/expressions.pyi +++ b/django-stubs/db/models/expressions.pyi @@ -57,8 +57,8 @@ class BaseExpression: is_summary: bool filterable: bool window_compatible: bool - def __init__(self, output_field: Field | None = ...) -> None: ... - def get_db_converters(self, connection: BaseDatabaseWrapper) -> list[Callable]: ... + def __init__(self, output_field: Field[Any, Any] | None = ...) -> None: ... + def get_db_converters(self, connection: BaseDatabaseWrapper) -> list[Callable[..., Any]]: ... def get_source_expressions(self) -> list[Any]: ... def set_source_expressions(self, exprs: Sequence[Combinable]) -> None: ... @property @@ -78,17 +78,17 @@ class BaseExpression: @property def conditional(self) -> bool: ... @property - def field(self) -> Field: ... + def field(self) -> Field[Any, Any]: ... @property - def output_field(self) -> Field: ... + def output_field(self) -> Field[Any, Any]: ... @property - def convert_value(self) -> Callable: ... + def convert_value(self) -> Callable[..., Any]: ... def get_lookup(self, lookup: str) -> type[Lookup] | None: ... def get_transform(self, name: str) -> type[Transform] | None: ... def relabeled_clone(self: Self, change_map: dict[str | None, str]) -> Self: ... def copy(self: Self) -> Self: ... def get_group_by_cols(self: Self, alias: str | None = ...) -> list[Self]: ... - def get_source_fields(self) -> list[Field | None]: ... + def get_source_fields(self) -> list[Field[Any, Any] | None]: ... def asc( self, *, @@ -113,7 +113,9 @@ class CombinedExpression(SQLiteNumericMixin, Expression): connector: str lhs: Combinable rhs: Combinable - def __init__(self, lhs: Combinable, connector: str, rhs: Combinable, output_field: Field | None = ...) -> None: ... + def __init__( + self, lhs: Combinable, connector: str, rhs: Combinable, output_field: Field[Any, Any] | None = ... + ) -> None: ... class DurationExpression(CombinedExpression): def compile(self, side: Combinable, compiler: SQLCompiler, connection: BaseDatabaseWrapper) -> _AsSqlType: ... @@ -162,7 +164,7 @@ class Func(SQLiteNumericMixin, Expression): arity: int | None source_expressions: list[Expression] extra: dict[Any, Any] - def __init__(self, *expressions: Any, output_field: Field | None = ..., **extra: Any) -> None: ... + def __init__(self, *expressions: Any, output_field: Field[Any, Any] | None = ..., **extra: Any) -> None: ... def as_sql( self, compiler: SQLCompiler, @@ -175,21 +177,21 @@ class Func(SQLiteNumericMixin, Expression): class Value(Expression): value: Any - def __init__(self, value: Any, output_field: Field | None = ...) -> None: ... + def __init__(self, value: Any, output_field: Field[Any, Any] | None = ...) -> None: ... class RawSQL(Expression): params: list[Any] sql: str - def __init__(self, sql: str, params: Sequence[Any], output_field: Field | None = ...) -> None: ... + def __init__(self, sql: str, params: Sequence[Any], output_field: Field[Any, Any] | None = ...) -> None: ... class Star(Expression): ... class Col(Expression): - target: Field + target: Field[Any, Any] alias: str contains_column_references: Literal[True] possibly_multivalued: Literal[False] - def __init__(self, alias: str, target: Field, output_field: Field | None = ...) -> None: ... + def __init__(self, alias: str, target: Field[Any, Any], output_field: Field[Any, Any] | None = ...) -> None: ... class Ref(Expression): def __init__(self, refs: str, source: Expression) -> None: ... @@ -200,7 +202,7 @@ class ExpressionList(Func): class OrderByList(Func): ... class ExpressionWrapper(Expression): - def __init__(self, expression: Q | Combinable, output_field: Field) -> None: ... + def __init__(self, expression: Q | Combinable, output_field: Field[Any, Any]) -> None: ... class When(Expression): template: str @@ -215,14 +217,16 @@ class Case(Expression): default: Any extra: Any def __init__( - self, *cases: Any, default: Any | None = ..., output_field: Field | None = ..., **extra: Any + self, *cases: Any, default: Any | None = ..., output_field: Field[Any, Any] | None = ..., **extra: Any ) -> None: ... class Subquery(BaseExpression, Combinable): template: str query: Query extra: dict[Any, Any] - def __init__(self, queryset: Query | QuerySet, output_field: Field | None = ..., **extra: Any) -> None: ... + def __init__( + self, queryset: Query | QuerySet, output_field: Field[Any, Any] | None = ..., **extra: Any + ) -> None: ... class Exists(Subquery): negated: bool @@ -255,7 +259,7 @@ class Window(SQLiteNumericMixin, Expression): partition_by: str | Iterable[BaseExpression | F] | F | BaseExpression | None = ..., order_by: Sequence[BaseExpression | F] | BaseExpression | F | None = ..., frame: WindowFrame | None = ..., - output_field: Field | None = ..., + output_field: Field[Any, Any] | None = ..., ) -> None: ... class WindowFrame(Expression): diff --git a/django-stubs/db/models/fields/__init__.pyi b/django-stubs/db/models/fields/__init__.pyi index 64567d248..3ca4ea49b 100644 --- a/django-stubs/db/models/fields/__init__.pyi +++ b/django-stubs/db/models/fields/__init__.pyi @@ -213,7 +213,7 @@ class Field(RegisterLookupMixin, Generic[_ST, _GT]): def has_default(self) -> bool: ... def get_default(self) -> Any: ... def check(self, **kwargs: Any) -> list[CheckMessage]: ... - def get_col(self, alias: str, output_field: Field | None = ...) -> Col: ... + def get_col(self, alias: str, output_field: Field[Any, Any] | None = ...) -> Col: ... @property def cached_col(self) -> Col: ... def value_from_object(self, obj: Model) -> _GT: ... diff --git a/django-stubs/db/models/fields/files.pyi b/django-stubs/db/models/fields/files.pyi index e5f098389..8a3059486 100644 --- a/django-stubs/db/models/fields/files.pyi +++ b/django-stubs/db/models/fields/files.pyi @@ -40,7 +40,7 @@ _M = TypeVar("_M", bound=Model, contravariant=True) class _UploadToCallable(Protocol[_M]): def __call__(self, __instance: _M, __filename: str) -> _PathCompatible: ... -class FileField(Field): +class FileField(Field[Any, Any]): storage: Storage upload_to: _PathCompatible | _UploadToCallable def __init__( diff --git a/django-stubs/db/models/fields/json.pyi b/django-stubs/db/models/fields/json.pyi index 63206bd86..b19a2dcfe 100644 --- a/django-stubs/db/models/fields/json.pyi +++ b/django-stubs/db/models/fields/json.pyi @@ -10,7 +10,7 @@ from django.utils.functional import _StrOrPromise from . import Field from .mixins import CheckFieldDefaultMixin -class JSONField(CheckFieldDefaultMixin, Field): +class JSONField(CheckFieldDefaultMixin, Field[Any, Any]): encoder: type[json.JSONEncoder] | None decoder: type[json.JSONDecoder] | None def __init__( diff --git a/django-stubs/db/models/fields/related.pyi b/django-stubs/db/models/fields/related.pyi index d4e90e61b..9eed3f011 100644 --- a/django-stubs/db/models/fields/related.pyi +++ b/django-stubs/db/models/fields/related.pyi @@ -54,7 +54,7 @@ class RelatedField(FieldCacheMixin, Field[_ST, _GT]): def get_limit_choices_to(self) -> _LimitChoicesTo: ... def related_query_name(self) -> str: ... @property - def target_field(self) -> Field: ... + def target_field(self) -> Field[Any, Any]: ... class ForeignObject(RelatedField[_ST, _GT]): remote_field: ForeignObjectRel @@ -94,15 +94,15 @@ class ForeignObject(RelatedField[_ST, _GT]): validators: Iterable[validators._ValidatorCallable] = ..., error_messages: _ErrorMessagesT | None = ..., ) -> None: ... - def resolve_related_fields(self) -> list[tuple[Field, Field]]: ... + def resolve_related_fields(self) -> list[tuple[Field[Any, Any], Field[Any, Any]]]: ... @property - def related_fields(self) -> list[tuple[Field, Field]]: ... + def related_fields(self) -> list[tuple[Field[Any, Any], Field[Any, Any]]]: ... @property - def reverse_related_fields(self) -> list[tuple[Field, Field]]: ... + def reverse_related_fields(self) -> list[tuple[Field[Any, Any], Field[Any, Any]]]: ... @property - def local_related_fields(self) -> tuple[Field, ...]: ... + def local_related_fields(self) -> tuple[Field[Any, Any], ...]: ... @property - def foreign_related_fields(self) -> tuple[Field, ...]: ... + def foreign_related_fields(self) -> tuple[Field[Any, Any], ...]: ... class ForeignKey(ForeignObject[_ST, _GT]): _pyi_private_set_type: Any | Combinable diff --git a/django-stubs/db/models/fields/related_descriptors.pyi b/django-stubs/db/models/fields/related_descriptors.pyi index 17fd95b0f..50e40cbd0 100644 --- a/django-stubs/db/models/fields/related_descriptors.pyi +++ b/django-stubs/db/models/fields/related_descriptors.pyi @@ -25,13 +25,13 @@ class ForwardManyToOneDescriptor: def get_queryset(self, **hints: Any) -> QuerySet: ... def get_prefetch_queryset( self, instances: list[Model], queryset: QuerySet | None = ... - ) -> tuple[QuerySet, Callable, Callable, bool, str, bool]: ... + ) -> tuple[QuerySet, Callable[..., Any], Callable[..., Any], bool, str, bool]: ... def get_object(self, instance: Model) -> Model: ... def __get__( self, instance: Model | None, cls: type[Model] | None = ... ) -> Model | ForwardManyToOneDescriptor | None: ... def __set__(self, instance: Model, value: Model | None) -> None: ... - def __reduce__(self) -> tuple[Callable, tuple[type[Model], str]]: ... + def __reduce__(self) -> tuple[Callable[..., Any], tuple[type[Model], str]]: ... class ForwardOneToOneDescriptor(ForwardManyToOneDescriptor): field: OneToOneField @@ -46,10 +46,10 @@ class ReverseOneToOneDescriptor: def get_queryset(self, **hints: Any) -> QuerySet: ... def get_prefetch_queryset( self, instances: list[Model], queryset: QuerySet | None = ... - ) -> tuple[QuerySet, Callable, Callable, bool, str, bool]: ... + ) -> tuple[QuerySet, Callable[..., Any], Callable[..., Any], bool, str, bool]: ... def __get__(self, instance: Model | None, cls: type[Model] | None = ...) -> Model | ReverseOneToOneDescriptor: ... def __set__(self, instance: Model, value: Model | None) -> None: ... - def __reduce__(self) -> tuple[Callable, tuple[type[Model], str]]: ... + def __reduce__(self) -> tuple[Callable[..., Any], tuple[type[Model], str]]: ... class ReverseManyToOneDescriptor: rel: ManyToOneRel diff --git a/django-stubs/db/models/fields/related_lookups.pyi b/django-stubs/db/models/fields/related_lookups.pyi index f97a1a032..ea06f5ab6 100644 --- a/django-stubs/db/models/fields/related_lookups.pyi +++ b/django-stubs/db/models/fields/related_lookups.pyi @@ -15,13 +15,17 @@ from django.db.models.lookups import ( class MultiColSource: alias: str - field: Field - sources: tuple[Field, Field] - targets: tuple[Field, Field] + field: Field[Any, Any] + sources: tuple[Field[Any, Any], Field[Any, Any]] + targets: tuple[Field[Any, Any], Field[Any, Any]] contains_aggregate: bool - output_field: Field + output_field: Field[Any, Any] def __init__( - self, alias: str, targets: tuple[Field, Field], sources: tuple[Field, Field], field: Field + self, + alias: str, + targets: tuple[Field[Any, Any], Field[Any, Any]], + sources: tuple[Field[Any, Any], Field[Any, Any]], + field: Field[Any, Any], ) -> None: ... def relabeled_clone(self, relabels: Mapping[str, str]) -> MultiColSource: ... def get_lookup(self, lookup: str) -> type[Lookup] | None: ... diff --git a/django-stubs/db/models/fields/reverse_related.pyi b/django-stubs/db/models/fields/reverse_related.pyi index 8274f773f..2141ca4df 100644 --- a/django-stubs/db/models/fields/reverse_related.pyi +++ b/django-stubs/db/models/fields/reverse_related.pyi @@ -29,7 +29,7 @@ class ForeignObjectRel(FieldCacheMixin): related_query_name: str | None limit_choices_to: _AllLimitChoicesTo | None parent_link: bool - on_delete: Callable + on_delete: Callable[..., Any] symmetrical: bool multiple: bool field_name: str | None @@ -41,7 +41,7 @@ class ForeignObjectRel(FieldCacheMixin): related_query_name: str | None = ..., limit_choices_to: _AllLimitChoicesTo | None = ..., parent_link: bool = ..., - on_delete: Callable = ..., + on_delete: Callable[..., Any] = ..., ) -> None: ... @property def hidden(self) -> bool: ... @@ -94,9 +94,9 @@ class ManyToOneRel(ForeignObjectRel): related_query_name: str | None = ..., limit_choices_to: _AllLimitChoicesTo | None = ..., parent_link: bool = ..., - on_delete: Callable = ..., + on_delete: Callable[..., Any] = ..., ) -> None: ... - def get_related_field(self) -> Field: ... + def get_related_field(self) -> Field[Any, Any]: ... class OneToOneRel(ManyToOneRel): field: OneToOneField @@ -109,7 +109,7 @@ class OneToOneRel(ManyToOneRel): related_query_name: str | None = ..., limit_choices_to: _AllLimitChoicesTo | None = ..., parent_link: bool = ..., - on_delete: Callable = ..., + on_delete: Callable[..., Any] = ..., ) -> None: ... class ManyToManyRel(ForeignObjectRel): @@ -129,4 +129,4 @@ class ManyToManyRel(ForeignObjectRel): through_fields: tuple[str, str] | None = ..., db_constraint: bool = ..., ) -> None: ... - def get_related_field(self) -> Field: ... + def get_related_field(self) -> Field[Any, Any]: ... diff --git a/django-stubs/db/models/functions/comparison.pyi b/django-stubs/db/models/functions/comparison.pyi index 7f96b6c03..47574ced1 100644 --- a/django-stubs/db/models/functions/comparison.pyi +++ b/django-stubs/db/models/functions/comparison.pyi @@ -5,7 +5,7 @@ from django.db.models.fields import Field from django.db.models.fields.json import JSONField class Cast(Func): - def __init__(self, expression: Any, output_field: str | Field) -> None: ... + def __init__(self, expression: Any, output_field: str | Field[Any, Any]) -> None: ... class Coalesce(Func): ... diff --git a/django-stubs/db/models/options.pyi b/django-stubs/db/models/options.pyi index 5fa1c47e2..8def67392 100644 --- a/django-stubs/db/models/options.pyi +++ b/django-stubs/db/models/options.pyi @@ -42,8 +42,8 @@ class Options(Generic[_M]): FORWARD_PROPERTIES: set[str] REVERSE_PROPERTIES: set[str] default_apps: Any - local_fields: list[Field] - local_many_to_many: list[ManyToManyField] + local_fields: list[Field[Any, Any]] + local_many_to_many: list[ManyToManyField[Any, Any]] private_fields: list[Any] local_managers: list[Manager] base_manager_name: str | None @@ -67,15 +67,15 @@ class Options(Generic[_M]): required_db_features: list[str] required_db_vendor: Literal["sqlite", "postgresql", "mysql", "oracle"] | None meta: type | None - pk: Field | None - auto_field: AutoField | None + pk: Field[Any, Any] | None + auto_field: AutoField[Any, Any] | None abstract: bool managed: bool proxy: bool proxy_for_model: type[Model] | None concrete_model: type[Model] | None swappable: str | None - parents: dict[type[Model], GenericForeignKey | Field] + parents: dict[type[Model], GenericForeignKey | Field[Any, Any]] auto_created: bool related_fkey_lookups: list[Any] apps: Apps @@ -114,10 +114,10 @@ class Options(Generic[_M]): def default_manager(self) -> Manager | None: ... @property def fields(self) -> ImmutableList[Field[Any, Any]]: ... - def get_field(self, field_name: str) -> Field | ForeignObjectRel | GenericForeignKey: ... + def get_field(self, field_name: str) -> Field[Any, Any] | ForeignObjectRel | GenericForeignKey: ... def get_base_chain(self, model: type[Model]) -> list[type[Model]]: ... def get_parent_list(self) -> list[type[Model]]: ... - def get_ancestor_link(self, ancestor: type[Model]) -> OneToOneField | None: ... + def get_ancestor_link(self, ancestor: type[Model]) -> OneToOneField[Any, Any] | None: ... def get_path_to_parent(self, parent: type[Model]) -> list[PathInfo]: ... def get_path_from_parent(self, parent: type[Model]) -> list[PathInfo]: ... def get_fields( diff --git a/django-stubs/db/models/query_utils.pyi b/django-stubs/db/models/query_utils.pyi index b52f33865..4037717e8 100644 --- a/django-stubs/db/models/query_utils.pyi +++ b/django-stubs/db/models/query_utils.pyi @@ -45,8 +45,8 @@ class Q(tree.Node): class DeferredAttribute: field_name: str - field: Field - def __init__(self, field: Field) -> None: ... + field: Field[Any, Any] + def __init__(self, field: Field[Any, Any]) -> None: ... _R = TypeVar("_R", bound=type) @@ -65,7 +65,7 @@ class RegisterLookupMixin: def _unregister_lookup(cls, lookup: type[Lookup], lookup_name: str | None = ...) -> None: ... def select_related_descend( - field: Field, + field: Field[Any, Any], restricted: bool, requested: Mapping[str, Any] | None, load_fields: Collection[str] | None, diff --git a/django-stubs/db/models/signals.pyi b/django-stubs/db/models/signals.pyi index 13cb3c252..dfb9872cd 100644 --- a/django-stubs/db/models/signals.pyi +++ b/django-stubs/db/models/signals.pyi @@ -10,7 +10,7 @@ class_prepared: Signal class ModelSignal(Signal): def connect( # type: ignore self, - receiver: Callable, + receiver: Callable[..., Any], sender: type[Model] | str | None = ..., weak: bool = ..., dispatch_uid: str | None = ..., @@ -18,7 +18,7 @@ class ModelSignal(Signal): ) -> None: ... def disconnect( # type: ignore self, - receiver: Callable | None = ..., + receiver: Callable[..., Any] | None = ..., sender: type[Model] | str | None = ..., dispatch_uid: str | None = ..., apps: Apps | None = ..., diff --git a/django-stubs/db/models/sql/compiler.pyi b/django-stubs/db/models/sql/compiler.pyi index a7601c8b2..84c27eec1 100644 --- a/django-stubs/db/models/sql/compiler.pyi +++ b/django-stubs/db/models/sql/compiler.pyi @@ -82,9 +82,11 @@ class SQLCompiler: ) -> list[dict[str, Any]]: ... def get_select_for_update_of_arguments(self) -> list[Any]: ... def deferred_to_columns(self) -> dict[type[Model], set[str]]: ... - def get_converters(self, expressions: list[Expression]) -> dict[int, tuple[list[Callable], Expression]]: ... + def get_converters( + self, expressions: list[Expression] + ) -> dict[int, tuple[list[Callable[..., Any]], Expression]]: ... def apply_converters( - self, rows: Iterable[Iterable[Any]], converters: dict[int, tuple[list[Callable], Expression]] + self, rows: Iterable[Iterable[Any]], converters: dict[int, tuple[list[Callable[..., Any]], Expression]] ) -> Iterator[list[None | date | datetime | float | Decimal | UUID | bytes | str]]: ... def results_iter( self, diff --git a/django-stubs/db/models/sql/query.pyi b/django-stubs/db/models/sql/query.pyi index eb03b2dc9..0f345215b 100644 --- a/django-stubs/db/models/sql/query.pyi +++ b/django-stubs/db/models/sql/query.pyi @@ -36,7 +36,7 @@ class RawQuery: class Query(BaseExpression): related_ids: list[int] | None - related_updates: dict[type[Model], list[tuple[Field, None, int | str]]] + related_updates: dict[type[Model], list[tuple[Field[Any, Any], None, int | str]]] values: list[Any] alias_prefix: str subq_aliases: frozenset[Any] @@ -82,7 +82,7 @@ class Query(BaseExpression): annotations: dict[str, Expression] def __init__(self, model: type[Model] | None, where: type[WhereNode] = ..., alias_cols: bool = ...) -> None: ... @property - def output_field(self) -> Field: ... + def output_field(self) -> Field[Any, Any]: ... @property def has_select_fields(self) -> bool: ... @property @@ -99,7 +99,7 @@ class Query(BaseExpression): def has_results(self, using: str) -> bool: ... def explain(self, using: str, format: str | None = ..., **options: Any) -> str: ... def combine(self, rhs: Query, connector: str) -> None: ... - def deferred_to_data(self, target: dict[Any, Any], callback: Callable) -> None: ... + def deferred_to_data(self, target: dict[Any, Any], callback: Callable[..., Any]) -> None: ... def ref_alias(self, alias: str) -> None: ... def unref_alias(self, alias: str, amount: int = ...) -> None: ... def promote_joins(self, aliases: Iterable[str]) -> None: ... @@ -140,8 +140,8 @@ class Query(BaseExpression): reuse_with_filtered_relation: bool = ..., ) -> JoinInfo: ... def trim_joins( - self, targets: tuple[Field, ...], joins: list[str], path: list[PathInfo] - ) -> tuple[tuple[Field, ...], str, list[str]]: ... + self, targets: tuple[Field[Any, Any], ...], joins: list[str], path: list[PathInfo] + ) -> tuple[tuple[Field[Any, Any], ...], str, list[str]]: ... def resolve_ref( self, name: str, allow_joins: bool = ..., reuse: set[str] | None = ..., summarize: bool = ... ) -> Expression: ... @@ -182,7 +182,7 @@ class Query(BaseExpression): def add_immediate_loading(self, field_names: Iterable[str]) -> None: ... def get_loaded_field_names(self) -> dict[type[Model], set[str]]: ... def get_loaded_field_names_cb( - self, target: dict[type[Model], set[str]], model: type[Model], fields: set[Field] + self, target: dict[type[Model], set[str]], model: type[Model], fields: set[Field[Any, Any]] ) -> None: ... def set_annotation_mask(self, names: Iterable[str] | None) -> None: ... def append_annotation_mask(self, names: Iterable[str]) -> None: ... @@ -193,7 +193,7 @@ class Query(BaseExpression): @property def extra_select(self) -> dict[str, Any]: ... def trim_start(self, names_with_path: list[tuple[str, list[PathInfo]]]) -> tuple[str, bool]: ... - def is_nullable(self, field: Field) -> bool: ... + def is_nullable(self, field: Field[Any, Any]) -> bool: ... def check_filterable(self, expression: Any) -> None: ... def build_lookup(self, lookups: Sequence[str], lhs: Expression | Query, rhs: Any) -> Lookup: ... def try_transform(self, lhs: Expression | Query, name: str) -> Transform: ... diff --git a/django-stubs/db/models/sql/subqueries.pyi b/django-stubs/db/models/sql/subqueries.pyi index d3c3e024d..c3fad5124 100644 --- a/django-stubs/db/models/sql/subqueries.pyi +++ b/django-stubs/db/models/sql/subqueries.pyi @@ -22,19 +22,19 @@ class UpdateQuery(Query): where: WhereNode def update_batch(self, pk_list: list[int], values: dict[str, int | None], using: str) -> None: ... def add_update_values(self, values: dict[str, Any]) -> None: ... - def add_update_fields(self, values_seq: list[tuple[Field, type[Model] | None, Case]]) -> None: ... - def add_related_update(self, model: type[Model], field: Field, value: int | str) -> None: ... + def add_update_fields(self, values_seq: list[tuple[Field[Any, Any], type[Model] | None, Case]]) -> None: ... + def add_related_update(self, model: type[Model], field: Field[Any, Any], value: int | str) -> None: ... def get_related_updates(self) -> list[UpdateQuery]: ... class InsertQuery(Query): select: tuple where: WhereNode where_class: type[WhereNode] - fields: Iterable[Field] + fields: Iterable[Field[Any, Any]] objs: list[Model] raw: bool def __init__(self, *args: Any, ignore_conflicts: bool = ..., **kwargs: Any) -> None: ... - def insert_values(self, fields: Iterable[Field], objs: list[Model], raw: bool = ...) -> None: ... + def insert_values(self, fields: Iterable[Field[Any, Any]], objs: list[Model], raw: bool = ...) -> None: ... class AggregateQuery(Query): select: tuple diff --git a/django-stubs/db/transaction.pyi b/django-stubs/db/transaction.pyi index 346fd2d44..ba20c8767 100644 --- a/django-stubs/db/transaction.pyi +++ b/django-stubs/db/transaction.pyi @@ -20,9 +20,9 @@ def get_rollback(using: str | None = ...) -> bool: ... def set_rollback(rollback: bool, using: str | None = ...) -> None: ... @contextmanager def mark_for_rollback_on_error(using: str | None = ...) -> Iterator[None]: ... -def on_commit(func: Callable, using: str | None = ...) -> None: ... +def on_commit(func: Callable[..., Any], using: str | None = ...) -> None: ... -_C = TypeVar("_C", bound=Callable) # Any callable +_C = TypeVar("_C", bound=Callable[..., Any]) # Any callable # Don't inherit from ContextDecorator, so we can provide a more specific signature for __call__ class Atomic: diff --git a/django-stubs/dispatch/dispatcher.pyi b/django-stubs/dispatch/dispatcher.pyi index 7b70e8684..f55bb9164 100644 --- a/django-stubs/dispatch/dispatcher.pyi +++ b/django-stubs/dispatch/dispatcher.pyi @@ -12,13 +12,17 @@ class Signal: sender_receivers_cache: Any def __init__(self, providing_args: list[str] = ..., use_caching: bool = ...) -> None: ... def connect( - self, receiver: Callable, sender: object | None = ..., weak: bool = ..., dispatch_uid: str | None = ... + self, + receiver: Callable[..., Any], + sender: object | None = ..., + weak: bool = ..., + dispatch_uid: str | None = ..., ) -> None: ... def disconnect( - self, receiver: Callable | None = ..., sender: object | None = ..., dispatch_uid: str | None = ... + self, receiver: Callable[..., Any] | None = ..., sender: object | None = ..., dispatch_uid: str | None = ... ) -> bool: ... def has_listeners(self, sender: Any = ...) -> bool: ... - def send(self, sender: Any, **named: Any) -> list[tuple[Callable, str | None]]: ... - def send_robust(self, sender: Any, **named: Any) -> list[tuple[Callable, Exception | str]]: ... + def send(self, sender: Any, **named: Any) -> list[tuple[Callable[..., Any], str | None]]: ... + def send_robust(self, sender: Any, **named: Any) -> list[tuple[Callable[..., Any], Exception | str]]: ... -def receiver(signal: list[Signal] | Signal, **kwargs: Any) -> Callable: ... +def receiver(signal: list[Signal] | Signal, **kwargs: Any) -> Callable[..., Any]: ... diff --git a/django-stubs/forms/fields.pyi b/django-stubs/forms/fields.pyi index aec81189f..e20d65f1d 100644 --- a/django-stubs/forms/fields.pyi +++ b/django-stubs/forms/fields.pyi @@ -316,7 +316,7 @@ class CallableChoiceIterator: class ChoiceField(Field): choices: _PropertyDescriptor[ - _FieldChoices | _ChoicesCallable | CallableChoiceIterator, + _FieldChoices | _ChoicesCallable[..., Any] | CallableChoiceIterator, _FieldChoices | CallableChoiceIterator, ] widget: _ClassLevelWidgetT diff --git a/django-stubs/forms/forms.pyi b/django-stubs/forms/forms.pyi index b061f78ee..7b789ab7f 100644 --- a/django-stubs/forms/forms.pyi +++ b/django-stubs/forms/forms.pyi @@ -45,7 +45,7 @@ class BaseForm: renderer: BaseRenderer | None = ..., ) -> None: ... def order_fields(self, field_order: Iterable[str] | None) -> None: ... - def __iter__(self) -> Iterator[BoundField]: ... + def __iter__(self) -> Iterator[BoundField[Any, Any]]: ... def __getitem__(self, name: str) -> BoundField: ... @property def errors(self) -> ErrorDict: ... diff --git a/django-stubs/forms/models.pyi b/django-stubs/forms/models.pyi index db8025fbf..96ce81fb7 100644 --- a/django-stubs/forms/models.pyi +++ b/django-stubs/forms/models.pyi @@ -34,7 +34,7 @@ _Widgets: TypeAlias = dict[str, type[Widget] | Widget] _Labels: TypeAlias = dict[str, str] _HelpTexts: TypeAlias = dict[str, str] _ErrorMessages: TypeAlias = dict[str, dict[str, str]] -_FormFieldCallback: TypeAlias = Callable[[models.Field], Field] +_FormFieldCallback: TypeAlias = Callable[[models.Field[Any, Any]], Field] _M = TypeVar("_M", bound=Model) _ParentM = TypeVar("_ParentM", bound=Model) @@ -285,7 +285,7 @@ class ModelChoiceField(ChoiceField): def get_limit_choices_to(self) -> _LimitChoicesTo: ... def label_from_instance(self, obj: Model) -> str: ... choices: _PropertyDescriptor[ - _FieldChoices | _ChoicesCallable | CallableChoiceIterator, + _FieldChoices | _ChoicesCallable[..., Any] | CallableChoiceIterator, _FieldChoices | CallableChoiceIterator | ModelChoiceIterator, ] def prepare_value(self, value: Any) -> Any: ... diff --git a/django-stubs/forms/widgets.pyi b/django-stubs/forms/widgets.pyi index d9d950e8e..36d839b63 100644 --- a/django-stubs/forms/widgets.pyi +++ b/django-stubs/forms/widgets.pyi @@ -145,7 +145,7 @@ class CheckboxInput(Input): check_test: _CheckCallable input_type: str template_name: str - def __init__(self, attrs: _OptAttrs | None = ..., check_test: _CheckCallable | None = ...) -> None: ... + def __init__(self, attrs: _OptAttrs | None = ..., check_test: _CheckCallable[..., Any] | None = ...) -> None: ... class ChoiceWidget(Widget): allow_multiple_selected: bool diff --git a/django-stubs/middleware/cache.pyi b/django-stubs/middleware/cache.pyi index 642a96fb8..129c5168b 100644 --- a/django-stubs/middleware/cache.pyi +++ b/django-stubs/middleware/cache.pyi @@ -26,7 +26,7 @@ class CacheMiddleware(UpdateCacheMiddleware, FetchFromCacheMiddleware): cache: BaseCache def __init__( self, - get_response: Callable = ..., + get_response: Callable[..., Any] = ..., cache_timeout: float | None = ..., page_timeout: float | None = ..., **kwargs: Any diff --git a/django-stubs/middleware/csrf.pyi b/django-stubs/middleware/csrf.pyi index b39fb9504..348ccd256 100644 --- a/django-stubs/middleware/csrf.pyi +++ b/django-stubs/middleware/csrf.pyi @@ -24,7 +24,11 @@ def rotate_token(request: HttpRequest) -> None: ... class CsrfViewMiddleware(MiddlewareMixin): def process_request(self, request: HttpRequest) -> None: ... def process_view( - self, request: HttpRequest, callback: Callable | None, callback_args: tuple, callback_kwargs: dict[str, Any] + self, + request: HttpRequest, + callback: Callable[..., Any] | None, + callback_args: tuple, + callback_kwargs: dict[str, Any], ) -> HttpResponseForbidden | None: ... def process_response(self, request: HttpRequest, response: HttpResponseBase) -> HttpResponseBase: ... diff --git a/django-stubs/shortcuts.pyi b/django-stubs/shortcuts.pyi index 34aa2b713..bd76e9943 100644 --- a/django-stubs/shortcuts.pyi +++ b/django-stubs/shortcuts.pyi @@ -23,19 +23,19 @@ class SupportsGetAbsoluteUrl(Protocol): @overload def redirect( - to: Callable | str | SupportsGetAbsoluteUrl, *args: Any, permanent: Literal[True], **kwargs: Any + to: Callable[..., Any] | str | SupportsGetAbsoluteUrl, *args: Any, permanent: Literal[True], **kwargs: Any ) -> HttpResponsePermanentRedirect: ... @overload def redirect( - to: Callable | str | SupportsGetAbsoluteUrl, *args: Any, permanent: Literal[False] = ..., **kwargs: Any + to: Callable[..., Any] | str | SupportsGetAbsoluteUrl, *args: Any, permanent: Literal[False] = ..., **kwargs: Any ) -> HttpResponseRedirect: ... @overload def redirect( - to: Callable | str | SupportsGetAbsoluteUrl, *args: Any, permanent: bool, **kwargs: Any + to: Callable[..., Any] | str | SupportsGetAbsoluteUrl, *args: Any, permanent: bool, **kwargs: Any ) -> HttpResponseRedirect | HttpResponsePermanentRedirect: ... _T = TypeVar("_T", bound=Model) def get_object_or_404(klass: type[_T] | Manager[_T] | QuerySet[_T], *args: Any, **kwargs: Any) -> _T: ... def get_list_or_404(klass: type[_T] | Manager[_T] | QuerySet[_T], *args: Any, **kwargs: Any) -> list[_T]: ... -def resolve_url(to: Callable | Model | str, *args: Any, **kwargs: Any) -> str: ... +def resolve_url(to: Callable[..., Any] | Model | str, *args: Any, **kwargs: Any) -> str: ... diff --git a/django-stubs/template/backends/jinja2.pyi b/django-stubs/template/backends/jinja2.pyi index 49d5bdc11..a87179312 100644 --- a/django-stubs/template/backends/jinja2.pyi +++ b/django-stubs/template/backends/jinja2.pyi @@ -10,7 +10,7 @@ class Jinja2(BaseEngine): context_processors: list[str] def __init__(self, params: dict[str, Any]) -> None: ... @property - def template_context_processors(self) -> list[Callable]: ... + def template_context_processors(self) -> list[Callable[..., Any]]: ... class Origin: name: str diff --git a/django-stubs/template/base.pyi b/django-stubs/template/base.pyi index d2f5e4530..d266284b0 100644 --- a/django-stubs/template/base.pyi +++ b/django-stubs/template/base.pyi @@ -93,8 +93,8 @@ class DebugLexer(Lexer): class Parser: tokens: list[Token] | str - tags: dict[str, Callable] - filters: dict[str, Callable] + tags: dict[str, Callable[..., Any]] + filters: dict[str, Callable[..., Any]] command_stack: list[tuple[str, Token]] libraries: dict[str, Library] origin: Origin | None @@ -116,7 +116,7 @@ class Parser: def delete_first_token(self) -> None: ... def add_library(self, lib: Library) -> None: ... def compile_filter(self, token: str) -> FilterExpression: ... - def find_filter(self, filter_name: str) -> Callable: ... + def find_filter(self, filter_name: str) -> Callable[..., Any]: ... constant_string: str filter_raw_string: str @@ -129,7 +129,7 @@ class FilterExpression: def __init__(self, token: str, parser: Parser) -> None: ... def resolve(self, context: Context, ignore_failures: bool = ...) -> Any: ... @staticmethod - def args_check(name: str, func: Callable, provided: list[tuple[bool, Any]]) -> bool: ... + def args_check(name: str, func: Callable[..., Any], provided: list[tuple[bool, Any]]) -> bool: ... class Variable: var: dict[Any, Any] | str diff --git a/django-stubs/template/context.pyi b/django-stubs/template/context.pyi index 5b79664c4..cc1382bd1 100644 --- a/django-stubs/template/context.pyi +++ b/django-stubs/template/context.pyi @@ -75,7 +75,7 @@ class RequestContext(Context): self, request: HttpRequest, dict_: dict[str, Any] | None = ..., - processors: list[Callable] | None = ..., + processors: list[Callable[..., Any]] | None = ..., use_l10n: bool | None = ..., use_tz: bool | None = ..., autoescape: bool = ..., diff --git a/django-stubs/template/context_processors.pyi b/django-stubs/template/context_processors.pyi index 15020b8c8..b0ecccce8 100644 --- a/django-stubs/template/context_processors.pyi +++ b/django-stubs/template/context_processors.pyi @@ -1,5 +1,5 @@ from collections.abc import Callable -from typing import TypeVar +from typing import Any, TypeVar from django.http.request import HttpRequest from django.utils.functional import SimpleLazyObject @@ -7,7 +7,7 @@ from django.utils.functional import SimpleLazyObject _R = TypeVar("_R", bound=HttpRequest) def csrf(request: HttpRequest) -> dict[str, SimpleLazyObject]: ... -def debug(request: HttpRequest) -> dict[str, Callable | bool]: ... +def debug(request: HttpRequest) -> dict[str, Callable[..., Any] | bool]: ... def i18n(request: HttpRequest) -> dict[str, list[tuple[str, str]] | bool | str]: ... def tz(request: HttpRequest) -> dict[str, str]: ... def static(request: HttpRequest) -> dict[str, str]: ... diff --git a/django-stubs/template/defaultfilters.pyi b/django-stubs/template/defaultfilters.pyi index d0a29e474..628537325 100644 --- a/django-stubs/template/defaultfilters.pyi +++ b/django-stubs/template/defaultfilters.pyi @@ -9,7 +9,7 @@ from django.utils.safestring import SafeString register: Any -def stringfilter(func: Callable) -> Callable: ... +def stringfilter(func: Callable[..., Any]) -> Callable[..., Any]: ... def addslashes(value: str) -> str: ... def capfirst(value: str) -> str: ... def escapejs_filter(value: str) -> SafeString: ... diff --git a/django-stubs/template/engine.pyi b/django-stubs/template/engine.pyi index 2f5d9bcee..15b143caf 100644 --- a/django-stubs/template/engine.pyi +++ b/django-stubs/template/engine.pyi @@ -41,7 +41,7 @@ class Engine: @staticmethod def get_default() -> Engine: ... @property - def template_context_processors(self) -> Sequence[Callable]: ... + def template_context_processors(self) -> Sequence[Callable[..., Any]]: ... def get_template_builtins(self, builtins: list[str]) -> list[Library]: ... def get_template_libraries(self, libraries: dict[str, str]) -> dict[str, Library]: ... @property diff --git a/django-stubs/template/library.pyi b/django-stubs/template/library.pyi index 927918e2c..ec01c8df8 100644 --- a/django-stubs/template/library.pyi +++ b/django-stubs/template/library.pyi @@ -12,8 +12,8 @@ class InvalidTemplateLibrary(Exception): ... _C = TypeVar("_C", bound=Callable[..., Any]) class Library: - filters: dict[str, Callable] - tags: dict[str, Callable] + filters: dict[str, Callable[..., Any]] + tags: dict[str, Callable[..., Any]] def __init__(self) -> None: ... @overload def tag(self, name: _C) -> _C: ... @@ -35,7 +35,7 @@ class Library: def inclusion_tag( self, filename: Template | str, - func: Callable | None = ..., + func: Callable[..., Any] | None = ..., takes_context: bool | None = ..., name: str | None = ..., ) -> Callable[[_C], _C]: ... @@ -47,7 +47,7 @@ class TagHelperNode(Node): kwargs: Any def __init__( self, - func: Callable, + func: Callable[..., Any], takes_context: bool | None, args: list[FilterExpression], kwargs: dict[str, FilterExpression], @@ -56,7 +56,7 @@ class TagHelperNode(Node): class SimpleNode(TagHelperNode): args: list[FilterExpression] - func: Callable + func: Callable[..., Any] kwargs: dict[str, FilterExpression] origin: Origin takes_context: bool | None @@ -64,7 +64,7 @@ class SimpleNode(TagHelperNode): target_var: str | None def __init__( self, - func: Callable, + func: Callable[..., Any], takes_context: bool | None, args: list[FilterExpression], kwargs: dict[str, FilterExpression], @@ -73,7 +73,7 @@ class SimpleNode(TagHelperNode): class InclusionNode(TagHelperNode): args: list[FilterExpression] - func: Callable + func: Callable[..., Any] kwargs: dict[str, FilterExpression] origin: Origin takes_context: bool | None @@ -81,7 +81,7 @@ class InclusionNode(TagHelperNode): filename: Template | str def __init__( self, - func: Callable, + func: Callable[..., Any], takes_context: bool | None, args: list[FilterExpression], kwargs: dict[str, FilterExpression], diff --git a/django-stubs/template/response.pyi b/django-stubs/template/response.pyi index 4a3982174..3e0a7760a 100644 --- a/django-stubs/template/response.pyi +++ b/django-stubs/template/response.pyi @@ -40,7 +40,7 @@ class SimpleTemplateResponse(HttpResponse): def resolve_context(self, context: dict[str, Any] | None) -> dict[str, Any] | None: ... @property def rendered_content(self) -> str: ... - def add_post_render_callback(self, callback: Callable) -> None: ... + def add_post_render_callback(self, callback: Callable[..., Any]) -> None: ... def render(self) -> SimpleTemplateResponse: ... @property def is_rendered(self) -> bool: ... diff --git a/django-stubs/test/testcases.pyi b/django-stubs/test/testcases.pyi index ced8d84b3..805b4d99d 100644 --- a/django-stubs/test/testcases.pyi +++ b/django-stubs/test/testcases.pyi @@ -154,7 +154,7 @@ class SimpleTestCase(unittest.TestCase): ) -> Any: ... def assertFieldOutput( self, - fieldclass: type[EmailField], + fieldclass: type[EmailField[Any, Any]], valid: dict[str, str], invalid: dict[str, list[str]], field_args: Iterable[Any] | None = ..., @@ -210,14 +210,14 @@ class TestCase(TransactionTestCase): ) -> Generator[list[Callable[[], Any]], None, None]: ... class CheckCondition: - conditions: Sequence[tuple[Callable, str]] - def __init__(self, *conditions: tuple[Callable, str]) -> None: ... - def add_condition(self, condition: Callable, reason: str) -> CheckCondition: ... + conditions: Sequence[tuple[Callable[..., Any], str]] + def __init__(self, *conditions: tuple[Callable[..., Any], str]) -> None: ... + def add_condition(self, condition: Callable[..., Any], reason: str) -> CheckCondition: ... def __get__(self, instance: None, cls: type[TransactionTestCase] | None = ...) -> bool: ... -def skipIfDBFeature(*features: Any) -> Callable: ... -def skipUnlessDBFeature(*features: Any) -> Callable: ... -def skipUnlessAnyDBFeature(*features: Any) -> Callable: ... +def skipIfDBFeature(*features: Any) -> Callable[..., Any]: ... +def skipUnlessDBFeature(*features: Any) -> Callable[..., Any]: ... +def skipUnlessAnyDBFeature(*features: Any) -> Callable[..., Any]: ... class QuietWSGIRequestHandler(WSGIRequestHandler): ... diff --git a/django-stubs/test/utils.pyi b/django-stubs/test/utils.pyi index aace07828..19ca838e2 100644 --- a/django-stubs/test/utils.pyi +++ b/django-stubs/test/utils.pyi @@ -20,9 +20,9 @@ from typing_extensions import SupportsIndex, TypeAlias _TestClass: TypeAlias = type[SimpleTestCase] -_DecoratedTest: TypeAlias = Callable | _TestClass +_DecoratedTest: TypeAlias = Callable[..., Any] | _TestClass _DT = TypeVar("_DT", bound=_DecoratedTest) -_C = TypeVar("_C", bound=Callable) # Any callable +_C = TypeVar("_C", bound=Callable[..., Any]) # Any callable TZ_SUPPORT: bool @@ -76,11 +76,13 @@ class modify_settings(override_settings): class override_system_checks(TestContextDecorator): registry: CheckRegistry - new_checks: list[Callable] - deployment_checks: list[Callable] | None - def __init__(self, new_checks: list[Callable], deployment_checks: list[Callable] | None = ...) -> None: ... - old_checks: set[Callable] - old_deployment_checks: set[Callable] + new_checks: list[Callable[..., Any]] + deployment_checks: list[Callable[..., Any]] | None + def __init__( + self, new_checks: list[Callable[..., Any]], deployment_checks: list[Callable[..., Any]] | None = ... + ) -> None: ... + old_checks: set[Callable[..., Any]] + old_deployment_checks: set[Callable[..., Any]] class CaptureQueriesContext: connection: BaseDatabaseWrapper @@ -103,14 +105,14 @@ class CaptureQueriesContext: class ignore_warnings(TestContextDecorator): ignore_kwargs: dict[str, Any] - filter_func: Callable + filter_func: Callable[..., Any] def __init__(self, **kwargs: Any) -> None: ... catch_warnings: AbstractContextManager[list | None] requires_tz_support: Any @contextmanager -def isolate_lru_cache(lru_cache_object: Callable) -> Iterator[None]: ... +def isolate_lru_cache(lru_cache_object: Callable[..., Any]) -> Iterator[None]: ... class override_script_prefix(TestContextDecorator): prefix: str diff --git a/django-stubs/urls/base.pyi b/django-stubs/urls/base.pyi index 95e1c38b4..551136dbd 100644 --- a/django-stubs/urls/base.pyi +++ b/django-stubs/urls/base.pyi @@ -6,7 +6,7 @@ from typing_extensions import Literal def resolve(path: str, urlconf: str | None = ...) -> ResolverMatch: ... def reverse( - viewname: Callable | str | None, + viewname: Callable[..., Any] | str | None, urlconf: str | None = ..., args: Sequence[Any] | None = ..., kwargs: dict[str, Any] | None = ..., diff --git a/django-stubs/urls/resolvers.pyi b/django-stubs/urls/resolvers.pyi index dec8d28d7..20158fe03 100644 --- a/django-stubs/urls/resolvers.pyi +++ b/django-stubs/urls/resolvers.pyi @@ -10,7 +10,7 @@ from django.utils.datastructures import MultiValueDict from typing_extensions import TypeAlias class ResolverMatch: - func: Callable + func: Callable[..., Any] args: tuple[Any, ...] kwargs: dict[str, Any] url_name: str | None @@ -24,7 +24,7 @@ class ResolverMatch: _func_path: str def __init__( self, - func: Callable, + func: Callable[..., Any], args: tuple[Any, ...], kwargs: dict[str, Any], url_name: str | None = ..., @@ -83,13 +83,13 @@ class LocalePrefixPattern: class URLPattern: pattern: _Pattern - callback: Callable + callback: Callable[..., Any] default_args: dict[str, str] | None name: str | None def __init__( self, pattern: _Pattern, - callback: Callable, + callback: Callable[..., Any], default_args: dict[str, str] | None = ..., name: str | None = ..., ) -> None: ... @@ -126,7 +126,7 @@ class URLResolver: @property def url_patterns(self) -> list[_AnyURL]: ... def resolve(self, path: str) -> ResolverMatch: ... - def resolve_error_handler(self, view_type: int) -> Callable: ... + def resolve_error_handler(self, view_type: int) -> Callable[..., Any]: ... def reverse(self, lookup_view: str, *args: Any, **kwargs: Any) -> str: ... def _is_callback(self, name: str) -> bool: ... def _populate(self) -> None: ... diff --git a/django-stubs/urls/utils.pyi b/django-stubs/urls/utils.pyi index bfd09c115..8a2c15c6c 100644 --- a/django-stubs/urls/utils.pyi +++ b/django-stubs/urls/utils.pyi @@ -1,4 +1,5 @@ from collections.abc import Callable +from typing import Any -def get_callable(lookup_view: Callable | str) -> Callable: ... +def get_callable(lookup_view: Callable[..., Any] | str) -> Callable[..., Any]: ... def get_mod_func(callback: str) -> tuple[str, str]: ... diff --git a/django-stubs/utils/asyncio.pyi b/django-stubs/utils/asyncio.pyi index ed9f47504..51e0f4efe 100644 --- a/django-stubs/utils/asyncio.pyi +++ b/django-stubs/utils/asyncio.pyi @@ -1,7 +1,7 @@ from collections.abc import Callable from typing import Any, TypeVar, overload -_C = TypeVar("_C", bound=Callable) +_C = TypeVar("_C", bound=Callable[..., Any]) @overload def async_unsafe(message: str) -> Callable[[_C], _C]: ... diff --git a/django-stubs/utils/autoreload.pyi b/django-stubs/utils/autoreload.pyi index 740c74be1..d7d2b8839 100644 --- a/django-stubs/utils/autoreload.pyi +++ b/django-stubs/utils/autoreload.pyi @@ -70,5 +70,5 @@ class WatchmanReloader(BaseReloader): def stop(self) -> None: ... def get_reloader() -> BaseReloader: ... -def start_django(reloader: BaseReloader, main_func: Callable, *args: Any, **kwargs: Any) -> None: ... -def run_with_reloader(main_func: Callable, *args: Any, **kwargs: Any) -> None: ... +def start_django(reloader: BaseReloader, main_func: Callable[..., Any], *args: Any, **kwargs: Any) -> None: ... +def run_with_reloader(main_func: Callable[..., Any], *args: Any, **kwargs: Any) -> None: ... diff --git a/django-stubs/utils/crypto.pyi b/django-stubs/utils/crypto.pyi index c0eb7e74a..f9a1261d5 100644 --- a/django-stubs/utils/crypto.pyi +++ b/django-stubs/utils/crypto.pyi @@ -1,5 +1,6 @@ from collections.abc import Callable from hmac import HMAC +from typing import Any using_sysrandom: bool RANDOM_STRING_CHARS: str @@ -14,5 +15,5 @@ def pbkdf2( salt: bytes | str, iterations: int, dklen: int = ..., - digest: Callable | None = ..., + digest: Callable[..., Any] | None = ..., ) -> bytes: ... diff --git a/django-stubs/utils/decorators.pyi b/django-stubs/utils/decorators.pyi index 7cbab1393..5bb0b7b0b 100644 --- a/django-stubs/utils/decorators.pyi +++ b/django-stubs/utils/decorators.pyi @@ -1,19 +1,21 @@ from collections.abc import Callable, Iterable -from typing import TypeVar +from typing import Any, TypeVar from django.utils.deprecation import MiddlewareMixin from django.utils.functional import classproperty as classproperty from django.views.generic.base import View -_T = TypeVar("_T", bound=View | Callable) # Any callable -_CallableType = TypeVar("_CallableType", bound=Callable) +_T = TypeVar("_T", bound=View | Callable[..., Any]) # Any callable +_CallableType = TypeVar("_CallableType", bound=Callable[..., Any]) class classonlymethod(classmethod): ... -def method_decorator(decorator: Callable | Iterable[Callable], name: str = ...) -> Callable[[_T], _T]: ... -def decorator_from_middleware_with_args(middleware_class: type) -> Callable: ... -def decorator_from_middleware(middleware_class: type) -> Callable: ... -def make_middleware_decorator(middleware_class: type[MiddlewareMixin]) -> Callable: ... +def method_decorator( + decorator: Callable[..., Any] | Iterable[Callable[..., Any]], name: str = ... +) -> Callable[[_T], _T]: ... +def decorator_from_middleware_with_args(middleware_class: type) -> Callable[..., Any]: ... +def decorator_from_middleware(middleware_class: type) -> Callable[..., Any]: ... +def make_middleware_decorator(middleware_class: type[MiddlewareMixin]) -> Callable[..., Any]: ... def sync_and_async_middleware(func: _CallableType) -> _CallableType: ... def sync_only_middleware(func: _CallableType) -> _CallableType: ... def async_only_middleware(func: _CallableType) -> _CallableType: ... diff --git a/django-stubs/utils/deprecation.pyi b/django-stubs/utils/deprecation.pyi index e15e0ae0a..20e7dfd70 100644 --- a/django-stubs/utils/deprecation.pyi +++ b/django-stubs/utils/deprecation.pyi @@ -18,7 +18,7 @@ class warn_about_renamed_method: def __init__( self, class_name: str, old_method_name: str, new_method_name: str, deprecation_warning: type[DeprecationWarning] ) -> None: ... - def __call__(self, f: Callable) -> Callable: ... + def __call__(self, f: Callable[..., Any]) -> Callable[..., Any]: ... class RenameMethodsBase(type): renamed_methods: Any diff --git a/django-stubs/utils/feedgenerator.pyi b/django-stubs/utils/feedgenerator.pyi index 1001dc835..aabcb3fa9 100644 --- a/django-stubs/utils/feedgenerator.pyi +++ b/django-stubs/utils/feedgenerator.pyi @@ -40,7 +40,7 @@ class SyndicationFeed: comments: str | None = ..., unique_id: str | None = ..., unique_id_is_permalink: bool | None = ..., - categories: tuple | None = ..., + categories: tuple[Any] | None = ..., item_copyright: str | None = ..., ttl: int | None = ..., updateddate: datetime.datetime | None = ..., diff --git a/django-stubs/utils/functional.pyi b/django-stubs/utils/functional.pyi index bad2f7c63..ee3c056af 100644 --- a/django-stubs/utils/functional.pyi +++ b/django-stubs/utils/functional.pyi @@ -46,12 +46,12 @@ class _StrPromise(Promise, Sequence[str]): def __getattribute__(self, __name: str) -> Any: ... _StrOrPromise: TypeAlias = str | _StrPromise # noqa: Y047 -_C = TypeVar("_C", bound=Callable) +_C = TypeVar("_C", bound=Callable[..., Any]) def lazy(func: _C, *resultclasses: Any) -> _C: ... def lazystr(text: Any) -> _StrPromise: ... -def keep_lazy(*resultclasses: Any) -> Callable: ... -def keep_lazy_text(func: Callable) -> Callable: ... +def keep_lazy(*resultclasses: Any) -> Callable[..., Any]: ... +def keep_lazy_text(func: Callable[..., Any]) -> Callable[..., Any]: ... empty: object @@ -59,22 +59,22 @@ def new_method_proxy(func: Callable[..., _T]) -> Callable[..., _T]: ... class LazyObject: def __init__(self) -> None: ... - __getattr__: Callable + __getattr__: Callable[..., Any] def __setattr__(self, name: str, value: Any) -> None: ... def __delattr__(self, name: str) -> None: ... - def __reduce__(self) -> tuple[Callable, tuple[Model]]: ... + def __reduce__(self) -> tuple[Callable[..., Any], tuple[Model]]: ... def __copy__(self) -> LazyObject: ... - __bytes__: Callable - __bool__: Callable - __dir__: Callable - __ne__: Callable - __hash__: Callable - __getitem__: Callable - __setitem__: Callable - __delitem__: Callable - __iter__: Callable - __len__: Callable - __contains__: Callable + __bytes__: Callable[..., Any] + __bool__: Callable[..., Any] + __dir__: Callable[..., Any] + __ne__: Callable[..., Any] + __hash__: Callable[..., Any] + __getitem__: Callable[..., Any] + __setitem__: Callable[..., Any] + __delitem__: Callable[..., Any] + __iter__: Callable[..., Any] + __len__: Callable[..., Any] + __contains__: Callable[..., Any] def unpickle_lazyobject(wrapped: Model) -> Model: ... diff --git a/django-stubs/utils/log.pyi b/django-stubs/utils/log.pyi index b17b9db52..51a20101d 100644 --- a/django-stubs/utils/log.pyi +++ b/django-stubs/utils/log.pyi @@ -25,8 +25,8 @@ class AdminEmailHandler(logging.Handler): def format_subject(self, subject: str) -> str: ... class CallbackFilter(logging.Filter): - callback: Callable - def __init__(self, callback: Callable) -> None: ... + callback: Callable[..., Any] + def __init__(self, callback: Callable[..., Any]) -> None: ... def filter(self, record: str | LogRecord) -> bool: ... class RequireDebugFalse(logging.Filter): diff --git a/django-stubs/utils/safestring.pyi b/django-stubs/utils/safestring.pyi index 6dbb5870e..586c6bd73 100644 --- a/django-stubs/utils/safestring.pyi +++ b/django-stubs/utils/safestring.pyi @@ -17,7 +17,7 @@ class SafeString(str, SafeData): SafeText: TypeAlias = SafeString -_C = TypeVar("_C", bound=Callable) +_C = TypeVar("_C", bound=Callable[..., Any]) @overload def mark_safe(s: _SD) -> _SD: ... diff --git a/django-stubs/utils/termcolors.pyi b/django-stubs/utils/termcolors.pyi index b466c6a57..7e574e09b 100644 --- a/django-stubs/utils/termcolors.pyi +++ b/django-stubs/utils/termcolors.pyi @@ -8,7 +8,7 @@ RESET: str opt_dict: Mapping[str, str] def colorize(text: str | None = ..., opts: Sequence[str] = ..., **kwargs: Any) -> str: ... -def make_style(opts: tuple = ..., **kwargs: Any) -> Callable: ... +def make_style(opts: tuple[Any] = ..., **kwargs: Any) -> Callable[..., Any]: ... NOCOLOR_PALETTE: str DARK_PALETTE: str diff --git a/django-stubs/utils/translation/__init__.pyi b/django-stubs/utils/translation/__init__.pyi index 17fd17c5d..d8f063d54 100644 --- a/django-stubs/utils/translation/__init__.pyi +++ b/django-stubs/utils/translation/__init__.pyi @@ -12,19 +12,19 @@ LANGUAGE_SESSION_KEY: str class TranslatorCommentWarning(SyntaxWarning): ... class Trans: - activate: Callable + activate: Callable[..., Any] check_for_language: functools._lru_cache_wrapper - deactivate: Callable - deactivate_all: Callable - get_language: Callable - get_language_bidi: Callable - get_language_from_path: Callable - get_language_from_request: Callable - gettext: Callable - gettext_noop: Callable - ngettext: Callable - npgettext: Callable - pgettext: Callable + deactivate: Callable[..., Any] + deactivate_all: Callable[..., Any] + get_language: Callable[..., Any] + get_language_bidi: Callable[..., Any] + get_language_from_path: Callable[..., Any] + get_language_from_request: Callable[..., Any] + gettext: Callable[..., Any] + gettext_noop: Callable[..., Any] + ngettext: Callable[..., Any] + npgettext: Callable[..., Any] + pgettext: Callable[..., Any] def __getattr__(self, real_name: Any) -> Any: ... def gettext_noop(message: str) -> str: ... diff --git a/django-stubs/views/debug.pyi b/django-stubs/views/debug.pyi index 8d5d4044b..93a1694cd 100644 --- a/django-stubs/views/debug.pyi +++ b/django-stubs/views/debug.pyi @@ -12,7 +12,7 @@ CLEANSED_SUBSTITUTE: str CURRENT_DIR: Path class CallableSettingWrapper: - def __init__(self, callable_setting: Callable | type[Any]) -> None: ... + def __init__(self, callable_setting: Callable[..., Any] | type[Any]) -> None: ... def technical_500_response( request: HttpRequest, diff --git a/django-stubs/views/decorators/cache.pyi b/django-stubs/views/decorators/cache.pyi index 058da9b53..1d4c14948 100644 --- a/django-stubs/views/decorators/cache.pyi +++ b/django-stubs/views/decorators/cache.pyi @@ -3,6 +3,8 @@ from typing import Any, TypeVar _F = TypeVar("_F", bound=Callable[..., Any]) -def cache_page(timeout: float | None, *, cache: Any | None = ..., key_prefix: Any | None = ...) -> Callable: ... -def cache_control(**kwargs: Any) -> Callable: ... +def cache_page( + timeout: float | None, *, cache: Any | None = ..., key_prefix: Any | None = ... +) -> Callable[..., Any]: ... +def cache_control(**kwargs: Any) -> Callable[..., Any]: ... def never_cache(view_func: _F) -> _F: ... diff --git a/django-stubs/views/decorators/debug.pyi b/django-stubs/views/decorators/debug.pyi index 35d8e37eb..ad20bec66 100644 --- a/django-stubs/views/decorators/debug.pyi +++ b/django-stubs/views/decorators/debug.pyi @@ -1,5 +1,5 @@ from collections.abc import Callable from typing import Any -def sensitive_variables(*variables: Any) -> Callable: ... -def sensitive_post_parameters(*parameters: Any) -> Callable: ... +def sensitive_variables(*variables: Any) -> Callable[..., Any]: ... +def sensitive_post_parameters(*parameters: Any) -> Callable[..., Any]: ... diff --git a/django-stubs/views/decorators/http.pyi b/django-stubs/views/decorators/http.pyi index c03160b91..e48596dce 100644 --- a/django-stubs/views/decorators/http.pyi +++ b/django-stubs/views/decorators/http.pyi @@ -11,6 +11,8 @@ require_GET: Callable[[_F], _F] require_POST: Callable[[_F], _F] require_safe: Callable[[_F], _F] -def condition(etag_func: Callable | None = ..., last_modified_func: Callable | None = ...) -> Callable: ... +def condition( + etag_func: Callable[..., Any] | None = ..., last_modified_func: Callable[..., Any] | None = ... +) -> Callable[..., Any]: ... def etag(etag_func: Callable[..., Any]) -> Callable[[_F], _F]: ... def last_modified(last_modified_func: Callable[..., Any]) -> Callable[[_F], _F]: ... diff --git a/django-stubs/views/decorators/vary.pyi b/django-stubs/views/decorators/vary.pyi index 191a3eaa1..f971eb3a8 100644 --- a/django-stubs/views/decorators/vary.pyi +++ b/django-stubs/views/decorators/vary.pyi @@ -3,5 +3,5 @@ from typing import Any, TypeVar _F = TypeVar("_F", bound=Callable[..., Any]) -def vary_on_headers(*headers: Any) -> Callable: ... +def vary_on_headers(*headers: Any) -> Callable[..., Any]: ... def vary_on_cookie(func: _F) -> _F: ... diff --git a/django-stubs/views/i18n.pyi b/django-stubs/views/i18n.pyi index 4c242f5b3..4addf2cbb 100644 --- a/django-stubs/views/i18n.pyi +++ b/django-stubs/views/i18n.pyi @@ -14,7 +14,7 @@ def get_formats() -> dict[str, list[str] | int | str]: ... js_catalog_template: str class JavaScriptCatalog(View): - head: Callable + head: Callable[..., Any] domain: str packages: list[str] translation: DjangoTranslation diff --git a/mypy.ini b/mypy.ini index ef5b0612f..1596da82e 100644 --- a/mypy.ini +++ b/mypy.ini @@ -14,6 +14,7 @@ warn_unused_configs = True warn_unreachable = True disallow_untyped_defs = true disallow_incomplete_defs = true +disallow_any_generics = true plugins = mypy_django_plugin.main diff --git a/tests/typecheck/db/models/test_init.yml b/tests/typecheck/db/models/test_init.yml index afa5b5f4b..8ec352756 100644 --- a/tests/typecheck/db/models/test_init.yml +++ b/tests/typecheck/db/models/test_init.yml @@ -2,7 +2,7 @@ main: | from django.db.models import Field - field: Field + field: Field[Any, Any] my_bool: bool my_bool = field.one_to_many From 72e4d7673f9d68ef273c0de6fddcbf41ee2399b0 Mon Sep 17 00:00:00 2001 From: Christian Bundy Date: Mon, 23 Jan 2023 22:04:52 -0800 Subject: [PATCH 14/36] Fix tuple --- django-stubs/apps/registry.pyi | 2 +- django-stubs/contrib/admin/actions.pyi | 5 ++++- django-stubs/contrib/admin/decorators.pyi | 2 +- django-stubs/contrib/admin/filters.pyi | 10 ++++----- django-stubs/contrib/admin/helpers.pyi | 22 +++++++++---------- django-stubs/contrib/admin/options.pyi | 2 +- django-stubs/contrib/admin/sites.pyi | 4 ++-- .../contrib/admin/templatetags/admin_list.pyi | 2 +- .../contrib/admin/views/autocomplete.pyi | 2 +- django-stubs/contrib/admin/views/main.pyi | 4 ++-- django-stubs/contrib/admindocs/middleware.pyi | 2 +- django-stubs/contrib/auth/admin.pyi | 5 +++-- django-stubs/contrib/flatpages/admin.pyi | 3 ++- django-stubs/contrib/gis/admin/options.pyi | 5 +++-- django-stubs/contrib/redirects/admin.pyi | 3 ++- django-stubs/contrib/sites/admin.pyi | 3 ++- .../db/models/fields/reverse_related.pyi | 2 +- django-stubs/db/models/query_utils.pyi | 2 +- django-stubs/db/models/sql/compiler.pyi | 2 +- django-stubs/db/models/sql/datastructures.pyi | 2 +- django-stubs/db/models/sql/query.pyi | 12 +++++----- django-stubs/db/models/sql/subqueries.pyi | 10 ++++----- django-stubs/middleware/csrf.pyi | 2 +- django-stubs/template/utils.pyi | 2 +- django-stubs/test/utils.pyi | 2 +- django-stubs/urls/resolvers.pyi | 8 +++---- django-stubs/utils/regex_helper.pyi | 8 +++---- 27 files changed, 68 insertions(+), 60 deletions(-) diff --git a/django-stubs/apps/registry.pyi b/django-stubs/apps/registry.pyi index 3d4175708..950c26368 100644 --- a/django-stubs/apps/registry.pyi +++ b/django-stubs/apps/registry.pyi @@ -13,7 +13,7 @@ class Apps: apps_ready: bool ready_event: threading.Event loading: bool - _pending_operations: dict[tuple[str, str], list] + _pending_operations: dict[tuple[str, str], list[Any]] models_ready: bool ready: bool def __init__(self, installed_apps: Iterable[AppConfig | str] | None = ...) -> None: ... diff --git a/django-stubs/contrib/admin/actions.pyi b/django-stubs/contrib/admin/actions.pyi index 767fc7100..d6646f5b1 100644 --- a/django-stubs/contrib/admin/actions.pyi +++ b/django-stubs/contrib/admin/actions.pyi @@ -1,6 +1,9 @@ from django.contrib.admin.options import ModelAdmin +from django.db.models import Model from django.db.models.query import QuerySet from django.http.request import HttpRequest from django.template.response import TemplateResponse -def delete_selected(modeladmin: ModelAdmin, request: HttpRequest, queryset: QuerySet) -> TemplateResponse | None: ... +def delete_selected( + modeladmin: ModelAdmin[Model], request: HttpRequest, queryset: QuerySet +) -> TemplateResponse | None: ... diff --git a/django-stubs/contrib/admin/decorators.pyi b/django-stubs/contrib/admin/decorators.pyi index 66664f37f..a8f09c424 100644 --- a/django-stubs/contrib/admin/decorators.pyi +++ b/django-stubs/contrib/admin/decorators.pyi @@ -11,7 +11,7 @@ from django.utils.functional import _StrOrPromise from typing_extensions import TypeAlias _Model = TypeVar("_Model", bound=Model) -_ModelAdmin = TypeVar("_ModelAdmin", bound=ModelAdmin) +_ModelAdmin = TypeVar("_ModelAdmin", bound=ModelAdmin[Model]) _Request = TypeVar("_Request", bound=HttpRequest) _QuerySet = TypeVar("_QuerySet", bound=QuerySet) # This is deliberately different from _DisplayT defined in contrib.admin.options diff --git a/django-stubs/contrib/admin/filters.pyi b/django-stubs/contrib/admin/filters.pyi index 9fd530360..a3b7c77cc 100644 --- a/django-stubs/contrib/admin/filters.pyi +++ b/django-stubs/contrib/admin/filters.pyi @@ -14,7 +14,7 @@ class ListFilter: template: str used_parameters: Any def __init__( - self, request: HttpRequest, params: dict[str, str], model: type[Model], model_admin: ModelAdmin + self, request: HttpRequest, params: dict[str, str], model: type[Model], model_admin: ModelAdmin[Model] ) -> None: ... def has_output(self) -> bool: ... def choices(self, changelist: Any) -> Iterator[dict[str, Any]]: ... @@ -25,7 +25,7 @@ class SimpleListFilter(ListFilter): parameter_name: str | None lookup_choices: Any def value(self) -> str | None: ... - def lookups(self, request: HttpRequest, model_admin: ModelAdmin) -> Iterable[tuple[Any, str]] | None: ... + def lookups(self, request: HttpRequest, model_admin: ModelAdmin[Model]) -> Iterable[tuple[Any, str]] | None: ... def choices(self, changelist: Any) -> Iterator[dict[str, Any]]: ... class FieldListFilter(ListFilter): @@ -38,7 +38,7 @@ class FieldListFilter(ListFilter): request: HttpRequest, params: dict[str, str], model: type[Model], - model_admin: ModelAdmin, + model_admin: ModelAdmin[Model], field_path: str, ) -> None: ... @classmethod @@ -52,7 +52,7 @@ class FieldListFilter(ListFilter): request: HttpRequest, params: dict[str, str], model: type[Model], - model_admin: ModelAdmin, + model_admin: ModelAdmin[Model], field_path: str, ) -> FieldListFilter: ... @@ -69,7 +69,7 @@ class RelatedFieldListFilter(FieldListFilter): @property def include_empty_choice(self) -> bool: ... def field_choices( - self, field: RelatedField, request: HttpRequest, model_admin: ModelAdmin + self, field: RelatedField, request: HttpRequest, model_admin: ModelAdmin[Model] ) -> list[tuple[str, str]]: ... def choices(self, changelist: Any) -> Iterator[dict[str, Any]]: ... diff --git a/django-stubs/contrib/admin/helpers.pyi b/django-stubs/contrib/admin/helpers.pyi index 420f73a4f..08f1c0853 100644 --- a/django-stubs/contrib/admin/helpers.pyi +++ b/django-stubs/contrib/admin/helpers.pyi @@ -27,7 +27,7 @@ class _PrepopulatedDict(TypedDict): class AdminForm: prepopulated_fields: list[_PrepopulatedDict] - model_admin: ModelAdmin | None + model_admin: ModelAdmin[Model] | None readonly_fields: Sequence[str] form: ModelForm fieldsets: list[tuple[Any, dict[str, list[str]]]] @@ -37,7 +37,7 @@ class AdminForm: fieldsets: list[tuple[Any, dict[str, list[str]]]], prepopulated_fields: Mapping[str, Iterable[str]], readonly_fields: Sequence[str] | None = ..., - model_admin: ModelAdmin | None = ..., + model_admin: ModelAdmin[Model] | None = ..., ) -> None: ... def __iter__(self) -> Iterator[Fieldset]: ... @property @@ -51,7 +51,7 @@ class Fieldset: form: ModelForm classes: str description: str | None - model_admin: ModelAdmin | None + model_admin: ModelAdmin[Model] | None readonly_fields: Sequence[str] def __init__( self, @@ -61,7 +61,7 @@ class Fieldset: fields: Sequence[str] = ..., classes: Iterable[str] = ..., description: str | None = ..., - model_admin: ModelAdmin | None = ..., + model_admin: ModelAdmin[Model] | None = ..., ) -> None: ... @property def media(self) -> Media: ... @@ -71,14 +71,14 @@ class Fieldline: form: ModelForm fields: Sequence[str] has_visible_field: bool - model_admin: ModelAdmin | None + model_admin: ModelAdmin[Model] | None readonly_fields: Sequence[str] def __init__( self, form: ModelForm, field: str | Sequence[str], readonly_fields: Sequence[str] | None = ..., - model_admin: ModelAdmin | None = ..., + model_admin: ModelAdmin[Model] | None = ..., ) -> None: ... def __iter__(self) -> Iterator[AdminField[Any, Any] | AdminReadonlyField[Any, Any]]: ... def errors(self) -> SafeString: ... @@ -101,7 +101,7 @@ class _FieldDictT(TypedDict): class AdminReadonlyField: field: _FieldDictT form: ModelForm - model_admin: ModelAdmin | None + model_admin: ModelAdmin[Model] | None is_first: bool is_checkbox: bool is_readonly: bool @@ -111,7 +111,7 @@ class AdminReadonlyField: form: ModelForm, field: Callable[[Model], Any] | str, is_first: bool, - model_admin: ModelAdmin | None = ..., + model_admin: ModelAdmin[Model] | None = ..., ) -> None: ... def label_tag(self) -> SafeString: ... def contents(self) -> SafeString: ... @@ -120,7 +120,7 @@ class InlineAdminFormSet: opts: Any formset: Any fieldsets: Any - model_admin: ModelAdmin | None + model_admin: ModelAdmin[Model] | None readonly_fields: Sequence[str] prepopulated_fields: dict[str, Any] classes: str @@ -135,7 +135,7 @@ class InlineAdminFormSet: fieldsets: Any, prepopulated_fields: dict[str, Any] | None = ..., readonly_fields: Sequence[str] | None = ..., - model_admin: ModelAdmin | None = ..., + model_admin: ModelAdmin[Model] | None = ..., has_add_permission: bool = ..., has_change_permission: bool = ..., has_delete_permission: bool = ..., @@ -164,7 +164,7 @@ class InlineAdminForm(AdminForm): prepopulated_fields: Any, original: bool | None, readonly_fields: Sequence[str] | None = ..., - model_admin: ModelAdmin | None = ..., + model_admin: ModelAdmin[Model] | None = ..., view_on_site_url: str | None = ..., ) -> None: ... def __iter__(self) -> Iterator[InlineFieldset]: ... diff --git a/django-stubs/contrib/admin/options.pyi b/django-stubs/contrib/admin/options.pyi index cd8ce0640..6d0c92163 100644 --- a/django-stubs/contrib/admin/options.pyi +++ b/django-stubs/contrib/admin/options.pyi @@ -134,7 +134,7 @@ class BaseModelAdmin(Generic[_ModelT]): def has_module_permission(self, request: HttpRequest) -> bool: ... _DisplayT: TypeAlias = _ListOrTuple[str | Callable[[_ModelT], str | bool]] -_ModelAdmin = TypeVar("_ModelAdmin", bound=ModelAdmin) +_ModelAdmin = TypeVar("_ModelAdmin", bound=ModelAdmin[_ModelT]) _ActionCallable: TypeAlias = Callable[[_ModelAdmin, HttpRequest, QuerySet[_ModelT]], HttpResponseBase | None] class ModelAdmin(BaseModelAdmin[_ModelT]): diff --git a/django-stubs/contrib/admin/sites.pyi b/django-stubs/contrib/admin/sites.pyi index 700aa41eb..8bda2b1b9 100644 --- a/django-stubs/contrib/admin/sites.pyi +++ b/django-stubs/contrib/admin/sites.pyi @@ -46,7 +46,7 @@ class AdminSite: empty_value_display: str final_catch_all_view: bool _empty_value_display: str - _registry: dict[type[Model], ModelAdmin] + _registry: dict[type[Model], ModelAdmin[Model]] _global_actions: dict[str, _ActionCallback] _actions: dict[str, _ActionCallback] def __init__(self, name: str = ...) -> None: ... @@ -54,7 +54,7 @@ class AdminSite: def register( self, model_or_iterable: type[Model] | Iterable[type[Model]], - admin_class: type[ModelAdmin] | None = ..., + admin_class: type[ModelAdmin[Model]] | None = ..., **options: Any ) -> None: ... def unregister(self, model_or_iterable: type[Model] | Iterable[type[Model]]) -> None: ... diff --git a/django-stubs/contrib/admin/templatetags/admin_list.pyi b/django-stubs/contrib/admin/templatetags/admin_list.pyi index 7eb3397b3..0667a4045 100644 --- a/django-stubs/contrib/admin/templatetags/admin_list.pyi +++ b/django-stubs/contrib/admin/templatetags/admin_list.pyi @@ -21,7 +21,7 @@ def pagination_tag(parser: Parser, token: Token) -> InclusionAdminNode: ... def result_headers(cl: ChangeList) -> Iterator[dict[str, int | str | None]]: ... def items_for_result(cl: ChangeList, result: Model, form: ModelForm | None) -> Iterator[SafeString]: ... -class ResultList(list): +class ResultList(list[Any]): form: ModelForm | None def __init__(self, form: ModelForm | None, *items: Any) -> None: ... diff --git a/django-stubs/contrib/admin/views/autocomplete.pyi b/django-stubs/contrib/admin/views/autocomplete.pyi index fc036b91a..8ac451009 100644 --- a/django-stubs/contrib/admin/views/autocomplete.pyi +++ b/django-stubs/contrib/admin/views/autocomplete.pyi @@ -6,6 +6,6 @@ from django.http.request import HttpRequest from django.views.generic.list import BaseListView class AutocompleteJsonView(BaseListView): - model_admin: ModelAdmin + model_admin: ModelAdmin[Model] term: Any def has_perm(self, request: HttpRequest, obj: Model | None = ...) -> bool: ... diff --git a/django-stubs/contrib/admin/views/main.pyi b/django-stubs/contrib/admin/views/main.pyi index fcc2a0417..12818383a 100644 --- a/django-stubs/contrib/admin/views/main.pyi +++ b/django-stubs/contrib/admin/views/main.pyi @@ -34,7 +34,7 @@ class ChangeList: list_select_related: bool | Sequence[str] list_per_page: int list_max_show_all: int - model_admin: ModelAdmin + model_admin: ModelAdmin[Model] preserved_filters: str sortable_by: Sequence[str] | None page_num: int @@ -61,7 +61,7 @@ class ChangeList: list_per_page: int, list_max_show_all: int, list_editable: Sequence[str], - model_admin: ModelAdmin, + model_admin: ModelAdmin[Model], sortable_by: Sequence[str] | None, ) -> None: ... def get_filters_params(self, params: dict[str, Any] | None = ...) -> dict[str, Any]: ... diff --git a/django-stubs/contrib/admindocs/middleware.pyi b/django-stubs/contrib/admindocs/middleware.pyi index d065145d7..c0add7de7 100644 --- a/django-stubs/contrib/admindocs/middleware.pyi +++ b/django-stubs/contrib/admindocs/middleware.pyi @@ -10,6 +10,6 @@ class XViewMiddleware(MiddlewareMixin): self, request: HttpRequest, view_func: Callable[..., HttpResponseBase], - view_args: tuple, + view_args: tuple[Any, ...], view_kwargs: dict[Any, Any], ) -> HttpResponse | None: ... diff --git a/django-stubs/contrib/auth/admin.pyi b/django-stubs/contrib/auth/admin.pyi index 209779e64..55a91d3cd 100644 --- a/django-stubs/contrib/auth/admin.pyi +++ b/django-stubs/contrib/auth/admin.pyi @@ -1,15 +1,16 @@ from typing import Any from django.contrib import admin +from django.db.models import Model from django.http.request import HttpRequest from django.http.response import HttpResponse csrf_protect_m: Any sensitive_post_parameters_m: Any -class GroupAdmin(admin.ModelAdmin): ... +class GroupAdmin(admin.ModelAdmin[Model]): ... -class UserAdmin(admin.ModelAdmin): +class UserAdmin(admin.ModelAdmin[Model]): change_user_password_template: Any add_fieldsets: Any add_form: Any diff --git a/django-stubs/contrib/flatpages/admin.pyi b/django-stubs/contrib/flatpages/admin.pyi index f17bd6190..9715958d5 100644 --- a/django-stubs/contrib/flatpages/admin.pyi +++ b/django-stubs/contrib/flatpages/admin.pyi @@ -1,8 +1,9 @@ from typing import Any from django.contrib import admin +from django.db.models import Model -class FlatPageAdmin(admin.ModelAdmin): +class FlatPageAdmin(admin.ModelAdmin[Model]): form: Any fieldsets: Any list_display: Any diff --git a/django-stubs/contrib/gis/admin/options.pyi b/django-stubs/contrib/gis/admin/options.pyi index a8e014c94..7b196ec0a 100644 --- a/django-stubs/contrib/gis/admin/options.pyi +++ b/django-stubs/contrib/gis/admin/options.pyi @@ -2,14 +2,15 @@ from typing import Any from django.contrib.admin import ModelAdmin from django.contrib.gis.forms import BaseGeometryWidget +from django.db.models import Model spherical_mercator_srid: int -class GISModelAdmin(ModelAdmin): +class GISModelAdmin(ModelAdmin[Model]): gis_widget: BaseGeometryWidget gis_widget_kwargs: dict[str, Any] -class GeoModelAdmin(ModelAdmin): +class GeoModelAdmin(ModelAdmin[Model]): default_lon: int default_lat: int default_zoom: int diff --git a/django-stubs/contrib/redirects/admin.pyi b/django-stubs/contrib/redirects/admin.pyi index 295fb8786..903d9247d 100644 --- a/django-stubs/contrib/redirects/admin.pyi +++ b/django-stubs/contrib/redirects/admin.pyi @@ -1,8 +1,9 @@ from typing import Any from django.contrib import admin +from django.db.models import Model -class RedirectAdmin(admin.ModelAdmin): +class RedirectAdmin(admin.ModelAdmin[Model]): list_display: Any list_filter: Any search_fields: Any diff --git a/django-stubs/contrib/sites/admin.pyi b/django-stubs/contrib/sites/admin.pyi index 5891cce4f..776276421 100644 --- a/django-stubs/contrib/sites/admin.pyi +++ b/django-stubs/contrib/sites/admin.pyi @@ -1,7 +1,8 @@ from typing import Any from django.contrib import admin +from django.db.models import Model -class SiteAdmin(admin.ModelAdmin): +class SiteAdmin(admin.ModelAdmin[Model]): list_display: Any search_fields: Any diff --git a/django-stubs/db/models/fields/reverse_related.pyi b/django-stubs/db/models/fields/reverse_related.pyi index 2141ca4df..9bfda9b9f 100644 --- a/django-stubs/db/models/fields/reverse_related.pyi +++ b/django-stubs/db/models/fields/reverse_related.pyi @@ -75,7 +75,7 @@ class ForeignObjectRel(FieldCacheMixin): ordering: Sequence[str] = ..., ) -> _ChoicesList: ... def is_hidden(self) -> bool: ... - def get_joining_columns(self) -> tuple: ... + def get_joining_columns(self) -> tuple[Any, ...]: ... def get_extra_restriction( self, where_class: type[WhereNode], alias: str, related_alias: str ) -> StartsWith | WhereNode | None: ... diff --git a/django-stubs/db/models/query_utils.pyi b/django-stubs/db/models/query_utils.pyi index 4037717e8..5274fd4ed 100644 --- a/django-stubs/db/models/query_utils.pyi +++ b/django-stubs/db/models/query_utils.pyi @@ -41,7 +41,7 @@ class Q(tree.Node): summarize: bool = ..., for_save: bool = ..., ) -> WhereNode: ... - def deconstruct(self) -> tuple[str, tuple, dict[str, str]]: ... + def deconstruct(self) -> tuple[str, tuple[Any, ...], dict[str, str]]: ... class DeferredAttribute: field_name: str diff --git a/django-stubs/db/models/sql/compiler.pyi b/django-stubs/db/models/sql/compiler.pyi index 84c27eec1..bb1c18d56 100644 --- a/django-stubs/db/models/sql/compiler.pyi +++ b/django-stubs/db/models/sql/compiler.pyi @@ -43,7 +43,7 @@ class SQLCompiler: order_by: list[tuple[Expression, tuple[str, _ParamsT, bool]]], ) -> list[_AsSqlType]: ... def collapse_group_by( - self, expressions: list[Expression], having: list[Expression] | tuple + self, expressions: list[Expression], having: list[Expression] | tuple[Any, ...] ) -> list[Expression]: ... def get_select( self, diff --git a/django-stubs/db/models/sql/datastructures.pyi b/django-stubs/db/models/sql/datastructures.pyi index fde898b1e..f82e12c10 100644 --- a/django-stubs/db/models/sql/datastructures.pyi +++ b/django-stubs/db/models/sql/datastructures.pyi @@ -17,7 +17,7 @@ class Join: parent_alias: str table_alias: str | None join_type: str - join_cols: tuple + join_cols: tuple[Any, ...] join_field: FieldCacheMixin nullable: bool filtered_relation: FilteredRelation | None diff --git a/django-stubs/db/models/sql/query.pyi b/django-stubs/db/models/sql/query.pyi index 0f345215b..c96cebfbd 100644 --- a/django-stubs/db/models/sql/query.pyi +++ b/django-stubs/db/models/sql/query.pyi @@ -32,7 +32,7 @@ class RawQuery: def get_columns(self) -> list[str]: ... def __iter__(self) -> Iterator[Any]: ... @property - def params_type(self) -> None | type[dict] | type[tuple]: ... + def params_type(self) -> None | type[dict] | type[tuple[Any, ...]]: ... class Query(BaseExpression): related_ids: list[int] | None @@ -60,17 +60,17 @@ class Query(BaseExpression): select_for_update: bool select_for_update_nowait: bool select_for_update_skip_locked: bool - select_for_update_of: tuple + select_for_update_of: tuple[Any, ...] select_for_no_key_update: bool select_related: dict[str, Any] | bool max_depth: int - values_select: tuple + values_select: tuple[Any, ...] annotation_select_mask: set[str] | None combinator: str | None combinator_all: bool - combined_queries: tuple + combined_queries: tuple[Any, ...] extra_select_mask: set[str] | None - extra_tables: tuple + extra_tables: tuple[Any, ...] extra_order_by: Sequence[Any] deferred_loading: tuple[set[str] | frozenset[str], bool] explain_query: bool @@ -87,7 +87,7 @@ class Query(BaseExpression): def has_select_fields(self) -> bool: ... @property def base_table(self) -> str: ... - def sql_with_params(self) -> tuple[str, tuple]: ... + def sql_with_params(self) -> tuple[str, tuple[Any, ...]]: ... def __deepcopy__(self, memo: dict[int, Any]) -> Query: ... def get_compiler(self, using: str | None = ..., connection: BaseDatabaseWrapper | None = ...) -> SQLCompiler: ... def get_meta(self) -> Options: ... diff --git a/django-stubs/db/models/sql/subqueries.pyi b/django-stubs/db/models/sql/subqueries.pyi index c3fad5124..61fed587a 100644 --- a/django-stubs/db/models/sql/subqueries.pyi +++ b/django-stubs/db/models/sql/subqueries.pyi @@ -9,14 +9,14 @@ from django.db.models.sql.query import Query from django.db.models.sql.where import WhereNode class DeleteQuery(Query): - select: tuple + select: tuple[Any, ...] where_class: type[WhereNode] where: WhereNode def do_query(self, table: str, where: WhereNode, using: str) -> int: ... def delete_batch(self, pk_list: list[int] | list[str], using: str) -> int: ... class UpdateQuery(Query): - select: tuple + select: tuple[Any, ...] where_class: type[WhereNode] def __init__(self, *args: Any, **kwargs: Any) -> None: ... where: WhereNode @@ -27,7 +27,7 @@ class UpdateQuery(Query): def get_related_updates(self) -> list[UpdateQuery]: ... class InsertQuery(Query): - select: tuple + select: tuple[Any, ...] where: WhereNode where_class: type[WhereNode] fields: Iterable[Field[Any, Any]] @@ -37,7 +37,7 @@ class InsertQuery(Query): def insert_values(self, fields: Iterable[Field[Any, Any]], objs: list[Model], raw: bool = ...) -> None: ... class AggregateQuery(Query): - select: tuple - sub_params: tuple + select: tuple[Any, ...] + sub_params: tuple[Any, ...] where: WhereNode where_class: type[WhereNode] diff --git a/django-stubs/middleware/csrf.pyi b/django-stubs/middleware/csrf.pyi index 348ccd256..3ee1fe4cf 100644 --- a/django-stubs/middleware/csrf.pyi +++ b/django-stubs/middleware/csrf.pyi @@ -27,7 +27,7 @@ class CsrfViewMiddleware(MiddlewareMixin): self, request: HttpRequest, callback: Callable[..., Any] | None, - callback_args: tuple, + callback_args: tuple[Any, ...], callback_kwargs: dict[str, Any], ) -> HttpResponseForbidden | None: ... def process_response(self, request: HttpRequest, response: HttpResponseBase) -> HttpResponseBase: ... diff --git a/django-stubs/template/utils.pyi b/django-stubs/template/utils.pyi index 4aaf8059f..6ae6e61a0 100644 --- a/django-stubs/template/utils.pyi +++ b/django-stubs/template/utils.pyi @@ -14,4 +14,4 @@ class EngineHandler: def __iter__(self) -> Iterator[Any]: ... def all(self) -> list[BaseEngine]: ... -def get_app_template_dirs(dirname: str) -> tuple: ... +def get_app_template_dirs(dirname: str) -> tuple[Any, ...]: ... diff --git a/django-stubs/test/utils.pyi b/django-stubs/test/utils.pyi index 19ca838e2..1aff4cb38 100644 --- a/django-stubs/test/utils.pyi +++ b/django-stubs/test/utils.pyi @@ -107,7 +107,7 @@ class ignore_warnings(TestContextDecorator): ignore_kwargs: dict[str, Any] filter_func: Callable[..., Any] def __init__(self, **kwargs: Any) -> None: ... - catch_warnings: AbstractContextManager[list | None] + catch_warnings: AbstractContextManager[list[Any] | None] requires_tz_support: Any diff --git a/django-stubs/urls/resolvers.pyi b/django-stubs/urls/resolvers.pyi index 20158fe03..3d554a8a7 100644 --- a/django-stubs/urls/resolvers.pyi +++ b/django-stubs/urls/resolvers.pyi @@ -38,7 +38,7 @@ class ResolverMatch: def __iter__(self) -> Iterator[Any]: ... def get_resolver(urlconf: str | None = ...) -> URLResolver: ... -def get_ns_resolver(ns_pattern: str, resolver: URLResolver, converters: tuple) -> URLResolver: ... +def get_ns_resolver(ns_pattern: str, resolver: URLResolver, converters: tuple[Any, ...]) -> URLResolver: ... _Pattern: TypeAlias = RegexPattern | RoutePattern | LocalePrefixPattern @@ -58,7 +58,7 @@ class RegexPattern(CheckURLMixin): name: str | None converters: dict[Any, Any] def __init__(self, regex: str, name: str | None = ..., is_endpoint: bool = ...) -> None: ... - def match(self, path: str) -> tuple[str, tuple, dict[str, str]] | None: ... + def match(self, path: str) -> tuple[str, tuple[Any, ...], dict[str, str]] | None: ... def check(self) -> list[CheckMessage]: ... class RoutePattern(CheckURLMixin): @@ -66,7 +66,7 @@ class RoutePattern(CheckURLMixin): name: str | None converters: dict[str, UUIDConverter] def __init__(self, route: str, name: str | None = ..., is_endpoint: bool = ...) -> None: ... - def match(self, path: str) -> tuple[str, tuple, dict[str, int | str]] | None: ... + def match(self, path: str) -> tuple[str, tuple[Any, ...], dict[str, int | str]] | None: ... def check(self) -> list[CheckMessage]: ... class LocalePrefixPattern: @@ -77,7 +77,7 @@ class LocalePrefixPattern: def regex(self) -> Pattern[str]: ... @property def language_prefix(self) -> str: ... - def match(self, path: str) -> tuple[str, tuple, dict[str, Any]] | None: ... + def match(self, path: str) -> tuple[str, tuple[Any, ...], dict[str, Any]] | None: ... def check(self) -> list[CheckMessage]: ... def describe(self) -> str: ... diff --git a/django-stubs/utils/regex_helper.pyi b/django-stubs/utils/regex_helper.pyi index 7cd62bbce..af27e947e 100644 --- a/django-stubs/utils/regex_helper.pyi +++ b/django-stubs/utils/regex_helper.pyi @@ -1,12 +1,12 @@ from collections.abc import Iterator, Mapping from re import Pattern -from typing import TypeVar +from typing import Any, TypeVar ESCAPE_MAPPINGS: Mapping[str, str | None] -class Choice(list): ... -class Group(list): ... -class NonCapture(list): ... +class Choice(list[Any]): ... +class Group(list[Any]): ... +class NonCapture(list[Any]): ... def normalize(pattern: str) -> list[tuple[str, list[str]]]: ... def next_char(input_iter: Iterator[str]) -> Iterator[tuple[str, bool]]: ... From 52931f93ae9d01e4e20064d539992dee8abac112 Mon Sep 17 00:00:00 2001 From: Christian Bundy Date: Mon, 23 Jan 2023 22:12:54 -0800 Subject: [PATCH 15/36] Fix accidental changes --- django-stubs/contrib/admin/helpers.pyi | 4 ++-- django-stubs/contrib/admin/options.pyi | 4 ++-- .../contrib/admin/templatetags/admin_list.pyi | 6 ++---- django-stubs/contrib/gis/db/models/fields.pyi | 16 ++++++++-------- .../db/migrations/operations/special.pyi | 4 ++-- django-stubs/forms/fields.pyi | 2 +- django-stubs/forms/forms.pyi | 2 +- django-stubs/forms/models.pyi | 2 +- django-stubs/forms/widgets.pyi | 2 +- django-stubs/test/testcases.pyi | 2 +- 10 files changed, 21 insertions(+), 23 deletions(-) diff --git a/django-stubs/contrib/admin/helpers.pyi b/django-stubs/contrib/admin/helpers.pyi index 08f1c0853..1d9fd9821 100644 --- a/django-stubs/contrib/admin/helpers.pyi +++ b/django-stubs/contrib/admin/helpers.pyi @@ -23,7 +23,7 @@ checkbox: Any class _PrepopulatedDict(TypedDict): field: BoundField - dependencies: list[BoundField[Any, Any]] + dependencies: list[BoundField] class AdminForm: prepopulated_fields: list[_PrepopulatedDict] @@ -80,7 +80,7 @@ class Fieldline: readonly_fields: Sequence[str] | None = ..., model_admin: ModelAdmin[Model] | None = ..., ) -> None: ... - def __iter__(self) -> Iterator[AdminField[Any, Any] | AdminReadonlyField[Any, Any]]: ... + def __iter__(self) -> Iterator[AdminField | AdminReadonlyField]: ... def errors(self) -> SafeString: ... class AdminField: diff --git a/django-stubs/contrib/admin/options.pyi b/django-stubs/contrib/admin/options.pyi index 6d0c92163..8cd1370dc 100644 --- a/django-stubs/contrib/admin/options.pyi +++ b/django-stubs/contrib/admin/options.pyi @@ -111,7 +111,7 @@ class BaseModelAdmin(Generic[_ModelT]): ) -> ModelChoiceField: ... def formfield_for_manytomany( self, db_field: ManyToManyField, request: HttpRequest, **kwargs: Any - ) -> ModelMultipleChoiceField[Any, Any] | None: ... + ) -> ModelMultipleChoiceField | None: ... def get_autocomplete_fields(self, request: HttpRequest) -> Sequence[str]: ... def get_view_on_site_url(self, obj: _ModelT | None = ...) -> str | None: ... def get_empty_value_display(self) -> SafeString: ... @@ -134,7 +134,7 @@ class BaseModelAdmin(Generic[_ModelT]): def has_module_permission(self, request: HttpRequest) -> bool: ... _DisplayT: TypeAlias = _ListOrTuple[str | Callable[[_ModelT], str | bool]] -_ModelAdmin = TypeVar("_ModelAdmin", bound=ModelAdmin[_ModelT]) +_ModelAdmin = TypeVar("_ModelAdmin", bound=ModelAdmin[Model]) _ActionCallable: TypeAlias = Callable[[_ModelAdmin, HttpRequest, QuerySet[_ModelT]], HttpResponseBase | None] class ModelAdmin(BaseModelAdmin[_ModelT]): diff --git a/django-stubs/contrib/admin/templatetags/admin_list.pyi b/django-stubs/contrib/admin/templatetags/admin_list.pyi index 0667a4045..8cf696c1f 100644 --- a/django-stubs/contrib/admin/templatetags/admin_list.pyi +++ b/django-stubs/contrib/admin/templatetags/admin_list.pyi @@ -26,12 +26,10 @@ class ResultList(list[Any]): def __init__(self, form: ModelForm | None, *items: Any) -> None: ... def results(cl: ChangeList) -> Iterator[ResultList]: ... -def result_hidden_fields(cl: ChangeList) -> Iterator[BoundField[Any, Any]]: ... +def result_hidden_fields(cl: ChangeList) -> Iterator[BoundField]: ... def result_list( cl: ChangeList, -) -> dict[ - str, list[dict[str, int | str | None]] | list[ResultList] | list[BoundField[Any, Any]] | ChangeList | int -]: ... +) -> dict[str, list[dict[str, int | str | None]] | list[ResultList] | list[BoundField] | ChangeList | int]: ... def result_list_tag(parser: Parser, token: Token) -> InclusionAdminNode: ... def date_hierarchy(cl: ChangeList) -> dict[str, Any] | None: ... def date_hierarchy_tag(parser: Parser, token: Token) -> InclusionAdminNode: ... diff --git a/django-stubs/contrib/gis/db/models/fields.pyi b/django-stubs/contrib/gis/db/models/fields.pyi index df7a5de3f..f1e8b68dd 100644 --- a/django-stubs/contrib/gis/db/models/fields.pyi +++ b/django-stubs/contrib/gis/db/models/fields.pyi @@ -30,7 +30,7 @@ class SRIDCacheEntry(NamedTuple): def get_srid_info(srid: int, connection: Any) -> SRIDCacheEntry: ... class BaseSpatialField(Field[_ST, _GT]): - form_class: type[forms.GeometryField[Any, Any]] + form_class: type[forms.GeometryField] geom_type: str geom_class: type[GEOSGeometry] | None geography: bool @@ -114,31 +114,31 @@ class GeometryField(BaseSpatialField): class PointField(GeometryField): geom_class: type[Point] - form_class: type[forms.PointField[Any, Any]] + form_class: type[forms.PointField] class LineStringField(GeometryField): geom_class: type[LineString] - form_class: type[forms.LineStringField[Any, Any]] + form_class: type[forms.LineStringField] class PolygonField(GeometryField): geom_class: type[Polygon] - form_class: type[forms.PolygonField[Any, Any]] + form_class: type[forms.PolygonField] class MultiPointField(GeometryField): geom_class: type[MultiPoint] - form_class: type[forms.MultiPointField[Any, Any]] + form_class: type[forms.MultiPointField] class MultiLineStringField(GeometryField): geom_class: type[MultiLineString] - form_class: type[forms.MultiLineStringField[Any, Any]] + form_class: type[forms.MultiLineStringField] class MultiPolygonField(GeometryField): geom_class: type[MultiPolygon] - form_class: type[forms.MultiPolygonField[Any, Any]] + form_class: type[forms.MultiPolygonField] class GeometryCollectionField(GeometryField): geom_class: type[GeometryCollection] - form_class: type[forms.GeometryCollectionField[Any, Any]] + form_class: type[forms.GeometryCollectionField] class ExtentField(Field[Any, Any]): def get_internal_type(self) -> Any: ... diff --git a/django-stubs/db/migrations/operations/special.pyi b/django-stubs/db/migrations/operations/special.pyi index 06c98302c..7698068d4 100644 --- a/django-stubs/db/migrations/operations/special.pyi +++ b/django-stubs/db/migrations/operations/special.pyi @@ -35,12 +35,12 @@ class _CodeCallable(Protocol): class RunPython(Operation): code: _CodeCallable - reverse_code: _CodeCallable[..., Any] | None + reverse_code: _CodeCallable | None hints: Mapping[str, Any] def __init__( self, code: _CodeCallable, - reverse_code: _CodeCallable[..., Any] | None = ..., + reverse_code: _CodeCallable | None = ..., atomic: bool | None = ..., hints: Mapping[str, Any] | None = ..., elidable: bool = ..., diff --git a/django-stubs/forms/fields.pyi b/django-stubs/forms/fields.pyi index e20d65f1d..aec81189f 100644 --- a/django-stubs/forms/fields.pyi +++ b/django-stubs/forms/fields.pyi @@ -316,7 +316,7 @@ class CallableChoiceIterator: class ChoiceField(Field): choices: _PropertyDescriptor[ - _FieldChoices | _ChoicesCallable[..., Any] | CallableChoiceIterator, + _FieldChoices | _ChoicesCallable | CallableChoiceIterator, _FieldChoices | CallableChoiceIterator, ] widget: _ClassLevelWidgetT diff --git a/django-stubs/forms/forms.pyi b/django-stubs/forms/forms.pyi index 7b789ab7f..b061f78ee 100644 --- a/django-stubs/forms/forms.pyi +++ b/django-stubs/forms/forms.pyi @@ -45,7 +45,7 @@ class BaseForm: renderer: BaseRenderer | None = ..., ) -> None: ... def order_fields(self, field_order: Iterable[str] | None) -> None: ... - def __iter__(self) -> Iterator[BoundField[Any, Any]]: ... + def __iter__(self) -> Iterator[BoundField]: ... def __getitem__(self, name: str) -> BoundField: ... @property def errors(self) -> ErrorDict: ... diff --git a/django-stubs/forms/models.pyi b/django-stubs/forms/models.pyi index 96ce81fb7..2748708e8 100644 --- a/django-stubs/forms/models.pyi +++ b/django-stubs/forms/models.pyi @@ -285,7 +285,7 @@ class ModelChoiceField(ChoiceField): def get_limit_choices_to(self) -> _LimitChoicesTo: ... def label_from_instance(self, obj: Model) -> str: ... choices: _PropertyDescriptor[ - _FieldChoices | _ChoicesCallable[..., Any] | CallableChoiceIterator, + _FieldChoices | _ChoicesCallable | CallableChoiceIterator, _FieldChoices | CallableChoiceIterator | ModelChoiceIterator, ] def prepare_value(self, value: Any) -> Any: ... diff --git a/django-stubs/forms/widgets.pyi b/django-stubs/forms/widgets.pyi index 36d839b63..d9d950e8e 100644 --- a/django-stubs/forms/widgets.pyi +++ b/django-stubs/forms/widgets.pyi @@ -145,7 +145,7 @@ class CheckboxInput(Input): check_test: _CheckCallable input_type: str template_name: str - def __init__(self, attrs: _OptAttrs | None = ..., check_test: _CheckCallable[..., Any] | None = ...) -> None: ... + def __init__(self, attrs: _OptAttrs | None = ..., check_test: _CheckCallable | None = ...) -> None: ... class ChoiceWidget(Widget): allow_multiple_selected: bool diff --git a/django-stubs/test/testcases.pyi b/django-stubs/test/testcases.pyi index 805b4d99d..afa6b0f42 100644 --- a/django-stubs/test/testcases.pyi +++ b/django-stubs/test/testcases.pyi @@ -154,7 +154,7 @@ class SimpleTestCase(unittest.TestCase): ) -> Any: ... def assertFieldOutput( self, - fieldclass: type[EmailField[Any, Any]], + fieldclass: type[EmailField], valid: dict[str, str], invalid: dict[str, list[str]], field_args: Iterable[Any] | None = ..., From 67bcbf6f11d6d7ec87fa6e528861bed1ccf6b162 Mon Sep 17 00:00:00 2001 From: Christian Bundy Date: Mon, 23 Jan 2023 22:13:54 -0800 Subject: [PATCH 16/36] Fix dict --- django-stubs/db/models/base.pyi | 2 +- django-stubs/db/models/sql/query.pyi | 2 +- django-stubs/forms/utils.pyi | 2 +- django-stubs/template/context.pyi | 2 +- 4 files changed, 4 insertions(+), 4 deletions(-) diff --git a/django-stubs/db/models/base.pyi b/django-stubs/db/models/base.pyi index 5070352a3..fc02fb16e 100644 --- a/django-stubs/db/models/base.pyi +++ b/django-stubs/db/models/base.pyi @@ -62,6 +62,6 @@ class Model(metaclass=ModelBase): def get_deferred_fields(self) -> set[str]: ... @classmethod def check(cls, **kwargs: Any) -> list[CheckMessage]: ... - def __getstate__(self) -> dict: ... + def __getstate__(self) -> dict[Any, Any]: ... def model_unpickle(model_id: tuple[str, str] | type[Model]) -> Model: ... diff --git a/django-stubs/db/models/sql/query.pyi b/django-stubs/db/models/sql/query.pyi index c96cebfbd..a73c25e72 100644 --- a/django-stubs/db/models/sql/query.pyi +++ b/django-stubs/db/models/sql/query.pyi @@ -32,7 +32,7 @@ class RawQuery: def get_columns(self) -> list[str]: ... def __iter__(self) -> Iterator[Any]: ... @property - def params_type(self) -> None | type[dict] | type[tuple[Any, ...]]: ... + def params_type(self) -> None | type[dict[Any, Any]] | type[tuple[Any, ...]]: ... class Query(BaseExpression): related_ids: list[int] | None diff --git a/django-stubs/forms/utils.pyi b/django-stubs/forms/utils.pyi index 95529f987..cbcfe7abf 100644 --- a/django-stubs/forms/utils.pyi +++ b/django-stubs/forms/utils.pyi @@ -16,7 +16,7 @@ _FilesT: TypeAlias = MultiValueDict[str, UploadedFile] # noqa: Y047 def pretty_name(name: str) -> str: ... def flatatt(attrs: dict[str, Any]) -> SafeString: ... -class ErrorDict(dict): +class ErrorDict(dict[Any, Any]): def as_data(self) -> dict[str, list[ValidationError]]: ... def get_json_data(self, escape_html: bool = ...) -> dict[str, Any]: ... def as_json(self, escape_html: bool = ...) -> str: ... diff --git a/django-stubs/template/context.pyi b/django-stubs/template/context.pyi index cc1382bd1..885599657 100644 --- a/django-stubs/template/context.pyi +++ b/django-stubs/template/context.pyi @@ -15,7 +15,7 @@ _ContextValues: TypeAlias = dict[str, Any] | Context class ContextPopException(Exception): ... -class ContextDict(dict): +class ContextDict(dict[Any, Any]): context: BaseContext def __init__(self, context: BaseContext, *args: Any, **kwargs: Any) -> None: ... def __enter__(self: Self) -> Self: ... From 12efe415134a5985423a04f184eb5960c49610a6 Mon Sep 17 00:00:00 2001 From: Christian Bundy Date: Mon, 23 Jan 2023 22:19:41 -0800 Subject: [PATCH 17/36] Fix QuerySet --- django-stubs/contrib/admin/actions.pyi | 2 +- django-stubs/contrib/admin/decorators.pyi | 2 +- django-stubs/contrib/admin/filters.pyi | 4 ++-- django-stubs/contrib/admin/options.pyi | 12 +++++++----- django-stubs/contrib/admin/sites.pyi | 2 +- django-stubs/contrib/admin/utils.pyi | 4 ++-- django-stubs/contrib/admin/views/main.pyi | 8 ++++---- django-stubs/contrib/contenttypes/fields.pyi | 4 ++-- django-stubs/contrib/contenttypes/models.pyi | 2 +- django-stubs/db/migrations/recorder.pyi | 2 +- django-stubs/db/models/expressions.pyi | 6 +++--- .../db/models/fields/related_descriptors.pyi | 14 +++++++------- django-stubs/db/models/query.pyi | 6 +++--- django-stubs/forms/models.pyi | 2 +- django-stubs/test/testcases.pyi | 2 +- tests/typecheck/contrib/admin/test_options.yml | 6 +++--- 16 files changed, 40 insertions(+), 38 deletions(-) diff --git a/django-stubs/contrib/admin/actions.pyi b/django-stubs/contrib/admin/actions.pyi index d6646f5b1..9d263ea55 100644 --- a/django-stubs/contrib/admin/actions.pyi +++ b/django-stubs/contrib/admin/actions.pyi @@ -5,5 +5,5 @@ from django.http.request import HttpRequest from django.template.response import TemplateResponse def delete_selected( - modeladmin: ModelAdmin[Model], request: HttpRequest, queryset: QuerySet + modeladmin: ModelAdmin[Model], request: HttpRequest, queryset: QuerySet[Model] ) -> TemplateResponse | None: ... diff --git a/django-stubs/contrib/admin/decorators.pyi b/django-stubs/contrib/admin/decorators.pyi index a8f09c424..e57837cb2 100644 --- a/django-stubs/contrib/admin/decorators.pyi +++ b/django-stubs/contrib/admin/decorators.pyi @@ -13,7 +13,7 @@ from typing_extensions import TypeAlias _Model = TypeVar("_Model", bound=Model) _ModelAdmin = TypeVar("_ModelAdmin", bound=ModelAdmin[Model]) _Request = TypeVar("_Request", bound=HttpRequest) -_QuerySet = TypeVar("_QuerySet", bound=QuerySet) +_QuerySet = TypeVar("_QuerySet", bound=QuerySet[Model]) # This is deliberately different from _DisplayT defined in contrib.admin.options _DisplayCallable: TypeAlias = Union[Callable[[_ModelAdmin, _Model], Any], Callable[[_Model], Any]] # noqa: Y037 _DisplayCallableT = TypeVar("_DisplayCallableT", bound=_DisplayCallable) diff --git a/django-stubs/contrib/admin/filters.pyi b/django-stubs/contrib/admin/filters.pyi index a3b7c77cc..b94d58f97 100644 --- a/django-stubs/contrib/admin/filters.pyi +++ b/django-stubs/contrib/admin/filters.pyi @@ -18,7 +18,7 @@ class ListFilter: ) -> None: ... def has_output(self) -> bool: ... def choices(self, changelist: Any) -> Iterator[dict[str, Any]]: ... - def queryset(self, request: HttpRequest, queryset: QuerySet) -> QuerySet | None: ... + def queryset(self, request: HttpRequest, queryset: QuerySet[Model]) -> QuerySet[Model] | None: ... def expected_parameters(self) -> list[str] | None: ... class SimpleListFilter(ListFilter): @@ -106,7 +106,7 @@ class AllValuesFieldListFilter(FieldListFilter): lookup_val: Any lookup_val_isnull: Any empty_value_display: str - lookup_choices: QuerySet + lookup_choices: QuerySet[Model] def choices(self, changelist: Any) -> Iterator[dict[str, Any]]: ... class RelatedOnlyFieldListFilter(RelatedFieldListFilter): diff --git a/django-stubs/contrib/admin/options.pyi b/django-stubs/contrib/admin/options.pyi index 8cd1370dc..87a9f8211 100644 --- a/django-stubs/contrib/admin/options.pyi +++ b/django-stubs/contrib/admin/options.pyi @@ -105,7 +105,9 @@ class BaseModelAdmin(Generic[_ModelT]): def formfield_for_choice_field( self, db_field: Field[Any, Any], request: HttpRequest, **kwargs: Any ) -> TypedChoiceField: ... - def get_field_queryset(self, db: str | None, db_field: RelatedField, request: HttpRequest) -> QuerySet | None: ... + def get_field_queryset( + self, db: str | None, db_field: RelatedField, request: HttpRequest + ) -> QuerySet[Model] | None: ... def formfield_for_foreignkey( self, db_field: ForeignKey, request: HttpRequest, **kwargs: Any ) -> ModelChoiceField: ... @@ -190,7 +192,7 @@ class ModelAdmin(BaseModelAdmin[_ModelT]): def get_paginator( self, request: HttpRequest, - queryset: QuerySet, + queryset: QuerySet[Model], per_page: int, orphans: int = ..., allow_empty_first_page: bool = ..., @@ -210,7 +212,7 @@ class ModelAdmin(BaseModelAdmin[_ModelT]): def get_list_select_related(self, request: HttpRequest) -> bool | Sequence[str]: ... def get_search_fields(self, request: HttpRequest) -> Sequence[str]: ... def get_search_results( - self, request: HttpRequest, queryset: QuerySet, search_term: str + self, request: HttpRequest, queryset: QuerySet[Model], search_term: str ) -> tuple[QuerySet[_ModelT], bool]: ... def get_preserved_filters(self, request: HttpRequest) -> str: ... def _get_edited_object_pks(self, request: HttpRequest, prefix: str) -> list[str]: ... @@ -229,7 +231,7 @@ class ModelAdmin(BaseModelAdmin[_ModelT]): def save_form(self, request: HttpRequest, form: Any, change: Any) -> Any: ... def save_model(self, request: HttpRequest, obj: _ModelT, form: Any, change: Any) -> None: ... def delete_model(self, request: HttpRequest, obj: _ModelT) -> None: ... - def delete_queryset(self, request: HttpRequest, queryset: QuerySet) -> None: ... + def delete_queryset(self, request: HttpRequest, queryset: QuerySet[Model]) -> None: ... def save_formset(self, request: HttpRequest, form: Any, formset: Any, change: Any) -> None: ... def save_related(self, request: HttpRequest, form: Any, formsets: Any, change: Any) -> None: ... def render_change_form( @@ -246,7 +248,7 @@ class ModelAdmin(BaseModelAdmin[_ModelT]): def response_post_save_add(self, request: HttpRequest, obj: _ModelT) -> HttpResponseRedirect: ... def response_post_save_change(self, request: HttpRequest, obj: _ModelT) -> HttpResponseRedirect: ... # Probably FileResponse cannot come from ModelAdmin views - def response_action(self, request: HttpRequest, queryset: QuerySet) -> HttpResponse | None: ... + def response_action(self, request: HttpRequest, queryset: QuerySet[Model]) -> HttpResponse | None: ... def response_delete(self, request: HttpRequest, obj_display: str, obj_id: int) -> HttpResponse: ... def render_delete_form(self, request: HttpRequest, context: dict[str, Any]) -> HttpResponse: ... def get_inline_formsets( diff --git a/django-stubs/contrib/admin/sites.pyi b/django-stubs/contrib/admin/sites.pyi index 8bda2b1b9..3603e3bfb 100644 --- a/django-stubs/contrib/admin/sites.pyi +++ b/django-stubs/contrib/admin/sites.pyi @@ -24,7 +24,7 @@ else: all_sites: MutableSet[AdminSite] -_ActionCallback: TypeAlias = Callable[[ModelAdmin, HttpRequest, QuerySet], TemplateResponse | None] +_ActionCallback: TypeAlias = Callable[[ModelAdmin, HttpRequest, QuerySet[Model]], TemplateResponse | None] class AlreadyRegistered(Exception): ... class NotRegistered(Exception): ... diff --git a/django-stubs/contrib/admin/utils.pyi b/django-stubs/contrib/admin/utils.pyi index f9e00a2ed..f3e8c8c7c 100644 --- a/django-stubs/contrib/admin/utils.pyi +++ b/django-stubs/contrib/admin/utils.pyi @@ -50,8 +50,8 @@ class _ModelFormatDict(TypedDict): verbose_name: str verbose_name_plural: str -def model_format_dict(obj: Model | type[Model] | QuerySet | Options[Model]) -> _ModelFormatDict: ... -def model_ngettext(obj: Options | QuerySet, n: int | None = ...) -> str: ... +def model_format_dict(obj: Model | type[Model] | QuerySet[Model] | Options[Model]) -> _ModelFormatDict: ... +def model_ngettext(obj: Options | QuerySet[Model], n: int | None = ...) -> str: ... def lookup_field( name: Callable[..., Any] | str, obj: Model, model_admin: BaseModelAdmin | None = ... ) -> tuple[Field[Any, Any] | None, str | None, Any]: ... diff --git a/django-stubs/contrib/admin/views/main.pyi b/django-stubs/contrib/admin/views/main.pyi index 12818383a..be18482f0 100644 --- a/django-stubs/contrib/admin/views/main.pyi +++ b/django-stubs/contrib/admin/views/main.pyi @@ -25,7 +25,7 @@ class ChangeList: model: type[Model] opts: Options lookup_opts: Options - root_queryset: QuerySet + root_queryset: QuerySet[Model] list_display: _DisplayT list_display_links: _DisplayT list_filter: Sequence[_ListFilterT] @@ -77,13 +77,13 @@ class ChangeList: paginator: Any def get_results(self, request: HttpRequest) -> None: ... def get_ordering_field(self, field_name: Callable[..., Any] | str) -> Expression | str | None: ... - def get_ordering(self, request: HttpRequest, queryset: QuerySet) -> list[Expression | str]: ... + def get_ordering(self, request: HttpRequest, queryset: QuerySet[Model]) -> list[Expression | str]: ... def get_ordering_field_columns(self) -> dict[int, Literal["desc", "asc"]]: ... - def get_queryset(self, request: HttpRequest) -> QuerySet: ... + def get_queryset(self, request: HttpRequest) -> QuerySet[Model]: ... filter_specs: list[ListFilter] has_filters: bool has_active_filters: bool clear_all_filters_qs: str - def apply_select_related(self, qs: QuerySet) -> QuerySet: ... + def apply_select_related(self, qs: QuerySet[Model]) -> QuerySet[Model]: ... def has_related_field_in_list_display(self) -> bool: ... def url_for_result(self, result: Model) -> str: ... diff --git a/django-stubs/contrib/contenttypes/fields.pyi b/django-stubs/contrib/contenttypes/fields.pyi index 19783ecc1..effb917c0 100644 --- a/django-stubs/contrib/contenttypes/fields.pyi +++ b/django-stubs/contrib/contenttypes/fields.pyi @@ -47,7 +47,7 @@ class GenericForeignKey(FieldCacheMixin): self, obj: Model | None = ..., id: int | None = ..., using: str | None = ... ) -> ContentType: ... def get_prefetch_queryset( - self, instances: list[Model] | QuerySet, queryset: QuerySet | None = ... + self, instances: list[Model] | QuerySet[Model], queryset: QuerySet[Model] | None = ... ) -> tuple[list[Model], Callable[..., Any], Callable[..., Any], bool, str, bool]: ... def __get__(self, instance: Model | None, cls: type[Model] | None = ...) -> Any | None: ... def __set__(self, instance: Model, value: Any | None) -> None: ... @@ -87,7 +87,7 @@ class GenericRelation(ForeignObject): def get_extra_restriction( self, where_class: type[WhereNode], alias: str | None, remote_alias: str ) -> WhereNode: ... - def bulk_related_objects(self, objs: list[Model], using: str = ...) -> QuerySet: ... + def bulk_related_objects(self, objs: list[Model], using: str = ...) -> QuerySet[Model]: ... class ReverseGenericManyToOneDescriptor(ReverseManyToOneDescriptor): ... diff --git a/django-stubs/contrib/contenttypes/models.pyi b/django-stubs/contrib/contenttypes/models.pyi index d54089ddd..27034a696 100644 --- a/django-stubs/contrib/contenttypes/models.pyi +++ b/django-stubs/contrib/contenttypes/models.pyi @@ -20,5 +20,5 @@ class ContentType(models.Model): def name(self) -> str: ... def model_class(self) -> type[Model] | None: ... def get_object_for_this_type(self, **kwargs: Any) -> Model: ... - def get_all_objects_for_this_type(self, **kwargs: Any) -> QuerySet: ... + def get_all_objects_for_this_type(self, **kwargs: Any) -> QuerySet[Model]: ... def natural_key(self) -> tuple[str, str]: ... diff --git a/django-stubs/db/migrations/recorder.pyi b/django-stubs/db/migrations/recorder.pyi index af95d9ce2..fefdb3d8c 100644 --- a/django-stubs/db/migrations/recorder.pyi +++ b/django-stubs/db/migrations/recorder.pyi @@ -12,7 +12,7 @@ class MigrationRecorder: connection: BaseDatabaseWrapper def __init__(self, connection: BaseDatabaseWrapper) -> None: ... @property - def migration_qs(self) -> QuerySet: ... + def migration_qs(self) -> QuerySet[Model]: ... def has_table(self) -> bool: ... def ensure_schema(self) -> None: ... def applied_migrations(self) -> dict[tuple[str, str], Migration]: ... diff --git a/django-stubs/db/models/expressions.pyi b/django-stubs/db/models/expressions.pyi index cfe4ac83d..de1584f49 100644 --- a/django-stubs/db/models/expressions.pyi +++ b/django-stubs/db/models/expressions.pyi @@ -5,7 +5,7 @@ from typing import Any, TypeVar from _typeshed import Self from django.db.backends.base.base import BaseDatabaseWrapper -from django.db.models import Q +from django.db.models import Model, Q from django.db.models.fields import Field from django.db.models.lookups import Lookup, Transform from django.db.models.query import QuerySet @@ -225,12 +225,12 @@ class Subquery(BaseExpression, Combinable): query: Query extra: dict[Any, Any] def __init__( - self, queryset: Query | QuerySet, output_field: Field[Any, Any] | None = ..., **extra: Any + self, queryset: Query | QuerySet[Model], output_field: Field[Any, Any] | None = ..., **extra: Any ) -> None: ... class Exists(Subquery): negated: bool - def __init__(self, queryset: Query | QuerySet, negated: bool = ..., **kwargs: Any) -> None: ... + def __init__(self, queryset: Query | QuerySet[Model], negated: bool = ..., **kwargs: Any) -> None: ... def __invert__(self) -> Exists: ... class OrderBy(Expression): diff --git a/django-stubs/db/models/fields/related_descriptors.pyi b/django-stubs/db/models/fields/related_descriptors.pyi index 50e40cbd0..254740423 100644 --- a/django-stubs/db/models/fields/related_descriptors.pyi +++ b/django-stubs/db/models/fields/related_descriptors.pyi @@ -22,10 +22,10 @@ class ForwardManyToOneDescriptor: @property def RelatedObjectDoesNotExist(self) -> type[ObjectDoesNotExist]: ... def is_cached(self, instance: Model) -> bool: ... - def get_queryset(self, **hints: Any) -> QuerySet: ... + def get_queryset(self, **hints: Any) -> QuerySet[Model]: ... def get_prefetch_queryset( - self, instances: list[Model], queryset: QuerySet | None = ... - ) -> tuple[QuerySet, Callable[..., Any], Callable[..., Any], bool, str, bool]: ... + self, instances: list[Model], queryset: QuerySet[Model] | None = ... + ) -> tuple[QuerySet[Model], Callable[..., Any], Callable[..., Any], bool, str, bool]: ... def get_object(self, instance: Model) -> Model: ... def __get__( self, instance: Model | None, cls: type[Model] | None = ... @@ -43,10 +43,10 @@ class ReverseOneToOneDescriptor: @property def RelatedObjectDoesNotExist(self) -> type[ObjectDoesNotExist]: ... def is_cached(self, instance: Model) -> bool: ... - def get_queryset(self, **hints: Any) -> QuerySet: ... + def get_queryset(self, **hints: Any) -> QuerySet[Model]: ... def get_prefetch_queryset( - self, instances: list[Model], queryset: QuerySet | None = ... - ) -> tuple[QuerySet, Callable[..., Any], Callable[..., Any], bool, str, bool]: ... + self, instances: list[Model], queryset: QuerySet[Model] | None = ... + ) -> tuple[QuerySet[Model], Callable[..., Any], Callable[..., Any], bool, str, bool]: ... def __get__(self, instance: Model | None, cls: type[Model] | None = ...) -> Model | ReverseOneToOneDescriptor: ... def __set__(self, instance: Model, value: Model | None) -> None: ... def __reduce__(self) -> tuple[Callable[..., Any], tuple[type[Model], str]]: ... @@ -74,6 +74,6 @@ class ManyToManyDescriptor(ReverseManyToOneDescriptor): # fake class _ForwardManyToManyManager(Generic[_T]): - def all(self) -> QuerySet: ... + def all(self) -> QuerySet[Model]: ... def create_forward_many_to_many_manager(superclass: type, rel: Any, reverse: Any) -> _ForwardManyToManyManager: ... diff --git a/django-stubs/db/models/query.pyi b/django-stubs/db/models/query.pyi index e89699d2f..fde8c3cfc 100644 --- a/django-stubs/db/models/query.pyi +++ b/django-stubs/db/models/query.pyi @@ -222,14 +222,14 @@ QuerySet: TypeAlias = _QuerySet[_T, _T] class Prefetch: prefetch_through: str prefetch_to: str - queryset: QuerySet | None + queryset: QuerySet[Model] | None to_attr: str | None - def __init__(self, lookup: str, queryset: QuerySet | None = ..., to_attr: str | None = ...) -> None: ... + def __init__(self, lookup: str, queryset: QuerySet[Model] | None = ..., to_attr: str | None = ...) -> None: ... def __getstate__(self) -> dict[str, Any]: ... def add_prefix(self, prefix: str) -> None: ... def get_current_prefetch_to(self, level: int) -> str: ... def get_current_to_attr(self, level: int) -> tuple[str, str]: ... - def get_current_queryset(self, level: int) -> QuerySet | None: ... + def get_current_queryset(self, level: int) -> QuerySet[Model] | None: ... def prefetch_related_objects(model_instances: Iterable[_T], *related_lookups: str | Prefetch) -> None: ... def get_prefetcher(instance: Model, through_attr: str, to_attr: str) -> tuple[Any, Any, bool, bool]: ... diff --git a/django-stubs/forms/models.pyi b/django-stubs/forms/models.pyi index 2748708e8..fa4a7df8c 100644 --- a/django-stubs/forms/models.pyi +++ b/django-stubs/forms/models.pyi @@ -247,7 +247,7 @@ class ModelChoiceIteratorValue: class ModelChoiceIterator: field: ModelChoiceField - queryset: QuerySet + queryset: QuerySet[Model] def __init__(self, field: ModelChoiceField) -> None: ... def __iter__(self) -> Iterator[tuple[ModelChoiceIteratorValue | str, str]]: ... def __len__(self) -> int: ... diff --git a/django-stubs/test/testcases.pyi b/django-stubs/test/testcases.pyi index afa6b0f42..f720da137 100644 --- a/django-stubs/test/testcases.pyi +++ b/django-stubs/test/testcases.pyi @@ -187,7 +187,7 @@ class TransactionTestCase(SimpleTestCase): serialized_rollback: bool def assertQuerysetEqual( self, - qs: Iterator[Any] | list[Model] | QuerySet | RawQuerySet, + qs: Iterator[Any] | list[Model] | QuerySet[Model] | RawQuerySet, values: Collection[Any], transform: Callable[[Model], Any] | type[str] = ..., ordered: bool = ..., diff --git a/tests/typecheck/contrib/admin/test_options.yml b/tests/typecheck/contrib/admin/test_options.yml index 18cfeb19c..0f101aaed 100644 --- a/tests/typecheck/contrib/admin/test_options.yml +++ b/tests/typecheck/contrib/admin/test_options.yml @@ -12,7 +12,7 @@ from django.db.models.query import QuerySet from django.utils.translation import gettext_lazy as _ - def an_action(modeladmin: "A", request: HttpRequest, queryset: QuerySet) -> None: + def an_action(modeladmin: "A", request: HttpRequest, queryset: QuerySet[Model]) -> None: pass class TestModel(models.Model): @@ -81,10 +81,10 @@ # this will fail if `model` has a type other than the generic specified in the class declaration model = TestModel - def a_method_action(self, request: HttpRequest, queryset: QuerySet) -> None: + def a_method_action(self, request: HttpRequest, queryset: QuerySet[Model]) -> None: pass - def a_method_action_with_message_user(self, request: HttpRequest, queryset: QuerySet) -> None: + def a_method_action_with_message_user(self, request: HttpRequest, queryset: QuerySet[Model]) -> None: self.message_user(request, _("Error message"), messages.ERROR) # This test is here to make sure we're not running into a mypy issue which is From 1d3b00a89e9db20d7fd5497d5e86d61c1f5529a3 Mon Sep 17 00:00:00 2001 From: Christian Bundy Date: Mon, 23 Jan 2023 22:21:50 -0800 Subject: [PATCH 18/36] Fix ModelForm --- django-stubs/contrib/admin/helpers.pyi | 22 +++++++++---------- .../contrib/admin/templatetags/admin_list.pyi | 6 ++--- django-stubs/contrib/contenttypes/forms.pyi | 2 +- django-stubs/contrib/flatpages/forms.pyi | 3 ++- django-stubs/forms/models.pyi | 4 ++-- 5 files changed, 19 insertions(+), 18 deletions(-) diff --git a/django-stubs/contrib/admin/helpers.pyi b/django-stubs/contrib/admin/helpers.pyi index 1d9fd9821..1fcb9faa5 100644 --- a/django-stubs/contrib/admin/helpers.pyi +++ b/django-stubs/contrib/admin/helpers.pyi @@ -29,11 +29,11 @@ class AdminForm: prepopulated_fields: list[_PrepopulatedDict] model_admin: ModelAdmin[Model] | None readonly_fields: Sequence[str] - form: ModelForm + form: ModelForm[Model] fieldsets: list[tuple[Any, dict[str, list[str]]]] def __init__( self, - form: ModelForm, + form: ModelForm[Model], fieldsets: list[tuple[Any, dict[str, list[str]]]], prepopulated_fields: Mapping[str, Iterable[str]], readonly_fields: Sequence[str] | None = ..., @@ -48,14 +48,14 @@ class AdminForm: def media(self) -> Media: ... class Fieldset: - form: ModelForm + form: ModelForm[Model] classes: str description: str | None model_admin: ModelAdmin[Model] | None readonly_fields: Sequence[str] def __init__( self, - form: ModelForm, + form: ModelForm[Model], name: Any | None = ..., readonly_fields: Sequence[str] = ..., fields: Sequence[str] = ..., @@ -68,14 +68,14 @@ class Fieldset: def __iter__(self) -> Iterator[Fieldline]: ... class Fieldline: - form: ModelForm + form: ModelForm[Model] fields: Sequence[str] has_visible_field: bool model_admin: ModelAdmin[Model] | None readonly_fields: Sequence[str] def __init__( self, - form: ModelForm, + form: ModelForm[Model], field: str | Sequence[str], readonly_fields: Sequence[str] | None = ..., model_admin: ModelAdmin[Model] | None = ..., @@ -88,7 +88,7 @@ class AdminField: is_first: bool is_checkbox: bool is_readonly: bool - def __init__(self, form: ModelForm, field: str, is_first: bool) -> None: ... + def __init__(self, form: ModelForm[Model], field: str, is_first: bool) -> None: ... def label_tag(self) -> SafeString: ... def errors(self) -> SafeString: ... @@ -100,7 +100,7 @@ class _FieldDictT(TypedDict): class AdminReadonlyField: field: _FieldDictT - form: ModelForm + form: ModelForm[Model] model_admin: ModelAdmin[Model] | None is_first: bool is_checkbox: bool @@ -108,7 +108,7 @@ class AdminReadonlyField: empty_value_display: Any def __init__( self, - form: ModelForm, + form: ModelForm[Model], field: Callable[[Model], Any] | str, is_first: bool, model_admin: ModelAdmin[Model] | None = ..., @@ -159,7 +159,7 @@ class InlineAdminForm(AdminForm): def __init__( self, formset: Any, - form: ModelForm, + form: ModelForm[Model], fieldsets: Any, prepopulated_fields: Any, original: bool | None, @@ -179,4 +179,4 @@ class InlineFieldset(Fieldset): def __iter__(self) -> Iterator[Fieldline]: ... class AdminErrorList(forms.utils.ErrorList): - def __init__(self, form: ModelForm, inline_formsets: Any) -> None: ... + def __init__(self, form: ModelForm[Model], inline_formsets: Any) -> None: ... diff --git a/django-stubs/contrib/admin/templatetags/admin_list.pyi b/django-stubs/contrib/admin/templatetags/admin_list.pyi index 8cf696c1f..9a9a517fd 100644 --- a/django-stubs/contrib/admin/templatetags/admin_list.pyi +++ b/django-stubs/contrib/admin/templatetags/admin_list.pyi @@ -19,11 +19,11 @@ def paginator_number(cl: ChangeList, i: int) -> SafeString: ... def pagination(cl: ChangeList) -> dict[str, Any]: ... def pagination_tag(parser: Parser, token: Token) -> InclusionAdminNode: ... def result_headers(cl: ChangeList) -> Iterator[dict[str, int | str | None]]: ... -def items_for_result(cl: ChangeList, result: Model, form: ModelForm | None) -> Iterator[SafeString]: ... +def items_for_result(cl: ChangeList, result: Model, form: ModelForm[Model] | None) -> Iterator[SafeString]: ... class ResultList(list[Any]): - form: ModelForm | None - def __init__(self, form: ModelForm | None, *items: Any) -> None: ... + form: ModelForm[Model] | None + def __init__(self, form: ModelForm[Model] | None, *items: Any) -> None: ... def results(cl: ChangeList) -> Iterator[ResultList]: ... def result_hidden_fields(cl: ChangeList) -> Iterator[BoundField]: ... diff --git a/django-stubs/contrib/contenttypes/forms.pyi b/django-stubs/contrib/contenttypes/forms.pyi index c5c7ddaf3..beb236b8a 100644 --- a/django-stubs/contrib/contenttypes/forms.pyi +++ b/django-stubs/contrib/contenttypes/forms.pyi @@ -4,7 +4,7 @@ from django.db.models import Model from django.forms.models import BaseModelFormSet, ModelForm _M = TypeVar("_M", bound=Model) -_ModelFormT = TypeVar("_ModelFormT", bound=ModelForm) +_ModelFormT = TypeVar("_ModelFormT", bound=ModelForm[Model]) class BaseGenericInlineFormSet(BaseModelFormSet[_M, _ModelFormT]): instance: Any diff --git a/django-stubs/contrib/flatpages/forms.pyi b/django-stubs/contrib/flatpages/forms.pyi index a33fa2309..79f9d3e0f 100644 --- a/django-stubs/contrib/flatpages/forms.pyi +++ b/django-stubs/contrib/flatpages/forms.pyi @@ -1,7 +1,8 @@ from typing import Any from django import forms +from django.db.models import Model -class FlatpageForm(forms.ModelForm): +class FlatpageForm(forms.ModelForm[Model]): url: Any def clean_url(self) -> str: ... diff --git a/django-stubs/forms/models.pyi b/django-stubs/forms/models.pyi index fa4a7df8c..bd5babbc3 100644 --- a/django-stubs/forms/models.pyi +++ b/django-stubs/forms/models.pyi @@ -111,7 +111,7 @@ def modelform_factory( field_classes: Mapping[str, type[Field]] | None = ..., ) -> type[ModelForm[_M]]: ... -_ModelFormT = TypeVar("_ModelFormT", bound=ModelForm) +_ModelFormT = TypeVar("_ModelFormT", bound=ModelForm[Model]) class BaseModelFormSet(Generic[_M, _ModelFormT], BaseFormSet[_ModelFormT]): model: type[_M] @@ -308,7 +308,7 @@ class ModelMultipleChoiceField(ModelChoiceField): def prepare_value(self, value: Any) -> Any: ... def has_changed(self, initial: Collection[Any] | None, data: Collection[Any] | None) -> bool: ... # type: ignore -def modelform_defines_fields(form_class: type[ModelForm]) -> bool: ... +def modelform_defines_fields(form_class: type[ModelForm[Model]]) -> bool: ... @overload def _get_foreign_key( # type: ignore parent_model: type[Model], model: type[Model], fk_name: str | None = ..., can_fail: Literal[True] = ... From 17fbf7c9b81ddb8d64344d6d546940840563fcfa Mon Sep 17 00:00:00 2001 From: Christian Bundy Date: Mon, 23 Jan 2023 22:23:18 -0800 Subject: [PATCH 19/36] Fix PostgresOperatorLookup --- django-stubs/contrib/postgres/fields/ranges.pyi | 14 +++++++------- django-stubs/contrib/postgres/lookups.pyi | 14 ++++++++------ django-stubs/db/models/fields/json.pyi | 6 +++--- 3 files changed, 18 insertions(+), 16 deletions(-) diff --git a/django-stubs/contrib/postgres/fields/ranges.pyi b/django-stubs/contrib/postgres/fields/ranges.pyi index 53b95fe6a..a394f7a7a 100644 --- a/django-stubs/contrib/postgres/fields/ranges.pyi +++ b/django-stubs/contrib/postgres/fields/ranges.pyi @@ -44,32 +44,32 @@ class DateTimeRangeField(RangeField): class DateRangeField(RangeField): def __get__(self, instance: Any, owner: Any) -> DateRange: ... -class DateTimeRangeContains(PostgresOperatorLookup): +class DateTimeRangeContains(PostgresOperatorLookup[Any]): lookup_name: str postgres_operator: str -class RangeContainedBy(PostgresOperatorLookup): +class RangeContainedBy(PostgresOperatorLookup[Any]): lookup_name: str type_mapping: dict[str, str] postgres_operator: str -class FullyLessThan(PostgresOperatorLookup): +class FullyLessThan(PostgresOperatorLookup[Any]): lookup_name: str postgres_operator: str -class FullGreaterThan(PostgresOperatorLookup): +class FullGreaterThan(PostgresOperatorLookup[Any]): lookup_name: str postgres_operator: str -class NotLessThan(PostgresOperatorLookup): +class NotLessThan(PostgresOperatorLookup[Any]): lookup_name: str postgres_operator: str -class NotGreaterThan(PostgresOperatorLookup): +class NotGreaterThan(PostgresOperatorLookup[Any]): lookup_name: str postgres_operator: str -class AdjacentToLookup(PostgresOperatorLookup): +class AdjacentToLookup(PostgresOperatorLookup[Any]): lookup_name: str postgres_operator: str diff --git a/django-stubs/contrib/postgres/lookups.pyi b/django-stubs/contrib/postgres/lookups.pyi index 247bed981..f978a68cb 100644 --- a/django-stubs/contrib/postgres/lookups.pyi +++ b/django-stubs/contrib/postgres/lookups.pyi @@ -1,14 +1,16 @@ +from typing import Any + from django.db.models import Lookup, Transform from django.db.models.lookups import Exact, PostgresOperatorLookup from .search import SearchVectorExact -class DataContains(PostgresOperatorLookup): ... -class ContainedBy(PostgresOperatorLookup): ... -class Overlap(PostgresOperatorLookup): ... -class HasKey(PostgresOperatorLookup): ... -class HasKeys(PostgresOperatorLookup): ... +class DataContains(PostgresOperatorLookup[Any]): ... +class ContainedBy(PostgresOperatorLookup[Any]): ... +class Overlap(PostgresOperatorLookup[Any]): ... +class HasKey(PostgresOperatorLookup[Any]): ... +class HasKeys(PostgresOperatorLookup[Any]): ... class HasAnyKeys(HasKeys): ... class Unaccent(Transform): ... class SearchLookup(SearchVectorExact): ... -class TrigramSimilar(PostgresOperatorLookup): ... +class TrigramSimilar(PostgresOperatorLookup[Any]): ... diff --git a/django-stubs/db/models/fields/json.pyi b/django-stubs/db/models/fields/json.pyi index b19a2dcfe..86e03ae9f 100644 --- a/django-stubs/db/models/fields/json.pyi +++ b/django-stubs/db/models/fields/json.pyi @@ -22,10 +22,10 @@ class JSONField(CheckFieldDefaultMixin, Field[Any, Any]): **kwargs: Any ) -> None: ... -class DataContains(PostgresOperatorLookup): ... -class ContainedBy(PostgresOperatorLookup): ... +class DataContains(PostgresOperatorLookup[Any]): ... +class ContainedBy(PostgresOperatorLookup[Any]): ... -class HasKeyLookup(PostgresOperatorLookup): +class HasKeyLookup(PostgresOperatorLookup[Any]): logical_operator: str | None class HasKey(HasKeyLookup): From 2f197356af48a2659a768cd05220a979f99950f2 Mon Sep 17 00:00:00 2001 From: Christian Bundy Date: Mon, 23 Jan 2023 22:26:46 -0800 Subject: [PATCH 20/36] Fix File --- django-stubs/contrib/admin/widgets.pyi | 12 ++++++++---- django-stubs/contrib/staticfiles/storage.pyi | 6 +++--- django-stubs/core/files/storage.pyi | 4 ++-- django-stubs/core/files/uploadedfile.pyi | 4 ++-- django-stubs/core/validators.pyi | 6 +++--- django-stubs/db/models/fields/files.pyi | 6 +++--- django-stubs/forms/fields.pyi | 6 +++--- django-stubs/forms/widgets.pyi | 4 ++-- 8 files changed, 26 insertions(+), 22 deletions(-) diff --git a/django-stubs/contrib/admin/widgets.pyi b/django-stubs/contrib/admin/widgets.pyi index 1f4db194e..b462f32c6 100644 --- a/django-stubs/contrib/admin/widgets.pyi +++ b/django-stubs/contrib/admin/widgets.pyi @@ -1,5 +1,5 @@ from collections.abc import Iterable, Mapping, Sequence -from typing import Any +from typing import Any, AnyStr from django import forms from django.contrib.admin.sites import AdminSite @@ -55,7 +55,9 @@ class ManyToManyRawIdWidget(ForeignKeyRawIdWidget): def url_parameters(self) -> dict[str, str]: ... def label_and_url_for_value(self, value: Any) -> tuple[str, str]: ... def format_value(self, value: Any) -> str | None: ... - def value_from_datadict(self, data: Mapping[str, Any], files: Mapping[str, Iterable[File]], name: str) -> Any: ... + def value_from_datadict( + self, data: Mapping[str, Any], files: Mapping[str, Iterable[File[AnyStr]]], name: str + ) -> Any: ... class RelatedFieldWidgetWrapper(forms.Widget): template_name: str @@ -81,9 +83,11 @@ class RelatedFieldWidgetWrapper(forms.Widget): def is_hidden(self) -> bool: ... def get_related_url(self, info: tuple[str, str], action: str, *args: Any) -> str: ... def get_context(self, name: str, value: Any, attrs: _OptAttrs | None) -> dict[str, Any]: ... - def value_from_datadict(self, data: Mapping[str, Any], files: Mapping[str, Iterable[File]], name: str) -> Any: ... + def value_from_datadict( + self, data: Mapping[str, Any], files: Mapping[str, Iterable[File[AnyStr]]], name: str + ) -> Any: ... def value_omitted_from_data( - self, data: Mapping[str, Any], files: Mapping[str, Iterable[File]], name: str + self, data: Mapping[str, Any], files: Mapping[str, Iterable[File[AnyStr]]], name: str ) -> bool: ... def id_for_label(self, id_: str) -> str: ... diff --git a/django-stubs/contrib/staticfiles/storage.pyi b/django-stubs/contrib/staticfiles/storage.pyi index ad294d211..da24f6b01 100644 --- a/django-stubs/contrib/staticfiles/storage.pyi +++ b/django-stubs/contrib/staticfiles/storage.pyi @@ -1,5 +1,5 @@ from collections.abc import Callable, Iterator -from typing import Any +from typing import Any, AnyStr from django.core.files.base import File from django.core.files.storage import FileSystemStorage, Storage @@ -24,8 +24,8 @@ class HashedFilesMixin: hashed_files: Any keep_intermediate_files: bool def __init__(self, *args: Any, **kwargs: Any) -> None: ... - def file_hash(self, name: str, content: File = ...) -> str: ... - def hashed_name(self, name: str, content: File | None = ..., filename: str | None = ...) -> str: ... + def file_hash(self, name: str, content: File[AnyStr] = ...) -> str: ... + def hashed_name(self, name: str, content: File[AnyStr] | None = ..., filename: str | None = ...) -> str: ... def url(self, name: str, force: bool = ...) -> str: ... def url_converter(self, name: str, hashed_files: dict[str, Any], template: str = ...) -> Callable[..., Any]: ... def post_process(self, paths: dict[str, Any], dry_run: bool = ..., **options: Any) -> _PostProcessT: ... diff --git a/django-stubs/core/files/storage.pyi b/django-stubs/core/files/storage.pyi index d34b0cded..354ca6b1d 100644 --- a/django-stubs/core/files/storage.pyi +++ b/django-stubs/core/files/storage.pyi @@ -1,12 +1,12 @@ from datetime import datetime -from typing import IO, Any +from typing import IO, Any, AnyStr from django.core.files.base import File from django.utils._os import _PathCompatible from django.utils.functional import LazyObject class Storage: - def open(self, name: str, mode: str = ...) -> File: ... + def open(self, name: str, mode: str = ...) -> File[AnyStr]: ... def save(self, name: str | None, content: IO[Any], max_length: int | None = ...) -> str: ... def get_valid_name(self, name: str) -> str: ... def get_alternative_name(self, file_root: str, file_ext: str) -> str: ... diff --git a/django-stubs/core/files/uploadedfile.pyi b/django-stubs/core/files/uploadedfile.pyi index 437da8d9b..e62699f4c 100644 --- a/django-stubs/core/files/uploadedfile.pyi +++ b/django-stubs/core/files/uploadedfile.pyi @@ -1,9 +1,9 @@ -from typing import IO, TypeVar +from typing import IO, AnyStr, TypeVar from _typeshed import Self from django.core.files.base import File -class UploadedFile(File): +class UploadedFile(File[AnyStr]): content_type: str | None charset: str | None content_type_extra: dict[str, str] | None diff --git a/django-stubs/core/validators.pyi b/django-stubs/core/validators.pyi index 4fa16d211..39d5930be 100644 --- a/django-stubs/core/validators.pyi +++ b/django-stubs/core/validators.pyi @@ -1,7 +1,7 @@ from collections.abc import Callable, Collection, Sequence, Sized from decimal import Decimal from re import Pattern, RegexFlag -from typing import Any +from typing import Any, AnyStr from django.core.files.base import File from django.utils.functional import _StrOrPromise @@ -125,10 +125,10 @@ class FileExtensionValidator: message: _StrOrPromise | None = ..., code: str | None = ..., ) -> None: ... - def __call__(self, value: File) -> None: ... + def __call__(self, value: File[AnyStr]) -> None: ... def get_available_image_extensions() -> Sequence[str]: ... -def validate_image_file_extension(value: File) -> None: ... +def validate_image_file_extension(value: File[AnyStr]) -> None: ... class ProhibitNullCharactersValidator: message: _StrOrPromise diff --git a/django-stubs/db/models/fields/files.pyi b/django-stubs/db/models/fields/files.pyi index 8a3059486..094a19cb8 100644 --- a/django-stubs/db/models/fields/files.pyi +++ b/django-stubs/db/models/fields/files.pyi @@ -1,5 +1,5 @@ from collections.abc import Callable, Iterable -from typing import Any, Protocol, TypeVar, overload +from typing import Any, AnyStr, Protocol, TypeVar, overload from _typeshed import Self from django.core import validators # due to weird mypy.stubtest error @@ -12,7 +12,7 @@ from django.db.models.query_utils import DeferredAttribute from django.utils._os import _PathCompatible from django.utils.functional import _StrOrPromise -class FieldFile(File): +class FieldFile(File[AnyStr]): instance: Model field: FileField storage: Storage @@ -25,7 +25,7 @@ class FieldFile(File): def url(self) -> str: ... @property def size(self) -> int: ... - def save(self, name: str, content: File, save: bool = ...) -> None: ... + def save(self, name: str, content: File[AnyStr], save: bool = ...) -> None: ... def delete(self, save: bool = ...) -> None: ... @property def closed(self) -> bool: ... diff --git a/django-stubs/forms/fields.pyi b/django-stubs/forms/fields.pyi index aec81189f..02e34e992 100644 --- a/django-stubs/forms/fields.pyi +++ b/django-stubs/forms/fields.pyi @@ -2,7 +2,7 @@ import datetime from collections.abc import Collection, Iterator, Sequence from decimal import Decimal from re import Pattern -from typing import Any, Protocol +from typing import Any, AnyStr, Protocol from uuid import UUID from django.core.files import File @@ -270,12 +270,12 @@ class FileField(Field): label_suffix: str | None = ..., ) -> None: ... def clean(self, data: Any, initial: Any | None = ...) -> Any: ... - def to_python(self, data: File | None) -> File | None: ... + def to_python(self, data: File[AnyStr] | None) -> File[AnyStr] | None: ... def bound_data(self, data: Any | None, initial: Any) -> Any: ... def has_changed(self, initial: Any | None, data: Any | None) -> bool: ... class ImageField(FileField): - def to_python(self, data: File | None) -> File | None: ... + def to_python(self, data: File[AnyStr] | None) -> File[AnyStr] | None: ... def widget_attrs(self, widget: Widget) -> dict[str, Any]: ... class URLField(CharField): diff --git a/django-stubs/forms/widgets.pyi b/django-stubs/forms/widgets.pyi index d9d950e8e..7f30b45db 100644 --- a/django-stubs/forms/widgets.pyi +++ b/django-stubs/forms/widgets.pyi @@ -1,6 +1,6 @@ import datetime from collections.abc import Iterable, Iterator, Mapping, Sequence -from typing import Any, Protocol +from typing import Any, AnyStr, Protocol from django.core.files.base import File from django.db.models.fields import _FieldChoices @@ -109,7 +109,7 @@ class ClearableFileInput(FileInput): template_name: str def clear_checkbox_name(self, name: str) -> str: ... def clear_checkbox_id(self, name: str) -> str: ... - def is_initial(self, value: File | str | None) -> bool: ... + def is_initial(self, value: File[AnyStr] | str | None) -> bool: ... def get_context(self, name: str, value: Any, attrs: _OptAttrs | None) -> dict[str, Any]: ... def value_from_datadict(self, data: _DataT, files: _FilesT, name: str) -> Any: ... def value_omitted_from_data(self, data: _DataT, files: _FilesT, name: str) -> bool: ... From 38f91fe0a990690a9e8169c8d352980be57b75c5 Mon Sep 17 00:00:00 2001 From: Christian Bundy Date: Mon, 23 Jan 2023 22:31:04 -0800 Subject: [PATCH 21/36] Fix Manager --- django-stubs/db/migrations/operations/models.pyi | 8 ++++---- django-stubs/db/migrations/state.pyi | 6 +++--- django-stubs/db/models/options.pyi | 12 ++++++------ 3 files changed, 13 insertions(+), 13 deletions(-) diff --git a/django-stubs/db/migrations/operations/models.pyi b/django-stubs/db/migrations/operations/models.pyi index 3809ac3be..056fd76db 100644 --- a/django-stubs/db/migrations/operations/models.pyi +++ b/django-stubs/db/migrations/operations/models.pyi @@ -20,14 +20,14 @@ class CreateModel(ModelOperation): fields: list[tuple[str, Field[Any, Any]]] options: dict[str, Any] bases: Sequence[type[Model] | str] | None - managers: Sequence[tuple[str, Manager]] | None + managers: Sequence[tuple[str, Manager[Model]]] | None def __init__( self, name: str, fields: list[tuple[str, Field[Any, Any]]], options: dict[str, Any] | None = ..., bases: Sequence[type[Model] | str] | None = ..., - managers: Sequence[tuple[str, Manager]] | None = ..., + managers: Sequence[tuple[str, Manager[Model]]] | None = ..., ) -> None: ... class DeleteModel(ModelOperation): ... @@ -89,8 +89,8 @@ class AlterModelOptions(ModelOptionOperation): def __init__(self, name: str, options: dict[str, Any]) -> None: ... class AlterModelManagers(ModelOptionOperation): - managers: Sequence[tuple[str, Manager]] - def __init__(self, name: str, managers: Sequence[tuple[str, Manager]]) -> None: ... + managers: Sequence[tuple[str, Manager[Model]]] + def __init__(self, name: str, managers: Sequence[tuple[str, Manager[Model]]]) -> None: ... class IndexOperation(Operation): option_name: str diff --git a/django-stubs/db/migrations/state.pyi b/django-stubs/db/migrations/state.pyi index f09dad798..9cea33a07 100644 --- a/django-stubs/db/migrations/state.pyi +++ b/django-stubs/db/migrations/state.pyi @@ -16,7 +16,7 @@ class ModelState: fields: dict[str, Field[Any, Any]] options: dict[str, Any] bases: Sequence[type[Model] | str] - managers: list[tuple[str, Manager]] + managers: list[tuple[str, Manager[Model]]] def __init__( self, app_label: str, @@ -24,10 +24,10 @@ class ModelState: fields: list[tuple[str, Field[Any, Any]]] | dict[str, Field[Any, Any]], options: dict[str, Any] | None = ..., bases: Sequence[type[Model] | str] | None = ..., - managers: list[tuple[str, Manager]] | None = ..., + managers: list[tuple[str, Manager[Model]]] | None = ..., ) -> None: ... def clone(self) -> ModelState: ... - def construct_managers(self) -> Iterator[tuple[str, Manager]]: ... + def construct_managers(self) -> Iterator[tuple[str, Manager[Model]]]: ... @classmethod def from_model(cls, model: type[Model], exclude_rels: bool = ...) -> ModelState: ... # Removed in 3.2, but back in 4.0 diff --git a/django-stubs/db/models/options.pyi b/django-stubs/db/models/options.pyi index 8def67392..31a3501d0 100644 --- a/django-stubs/db/models/options.pyi +++ b/django-stubs/db/models/options.pyi @@ -45,7 +45,7 @@ class Options(Generic[_M]): local_fields: list[Field[Any, Any]] local_many_to_many: list[ManyToManyField[Any, Any]] private_fields: list[Any] - local_managers: list[Manager] + local_managers: list[Manager[Model]] base_manager_name: str | None default_manager_name: str | None model_name: str | None @@ -92,7 +92,7 @@ class Options(Generic[_M]): @property def installed(self) -> bool: ... def contribute_to_class(self, cls: type[Model], name: str) -> None: ... - def add_manager(self, manager: Manager) -> None: ... + def add_manager(self, manager: Manager[Model]) -> None: ... def add_field(self, field: GenericForeignKey | Field[Any, Any], private: bool = ...) -> None: ... # if GenericForeignKey is passed as argument, it has primary_key = True set before def setup_pk(self, field: GenericForeignKey | Field[Any, Any]) -> None: ... @@ -105,13 +105,13 @@ class Options(Generic[_M]): @property def fields_map(self) -> dict[str, Field[Any, Any] | ForeignObjectRel]: ... @property - def managers(self) -> ImmutableList[Manager]: ... + def managers(self) -> ImmutableList[Manager[Model]]: ... @property - def managers_map(self) -> dict[str, Manager]: ... + def managers_map(self) -> dict[str, Manager[Model]]: ... @property - def base_manager(self) -> Manager: ... + def base_manager(self) -> Manager[Model]: ... @property - def default_manager(self) -> Manager | None: ... + def default_manager(self) -> Manager[Model] | None: ... @property def fields(self) -> ImmutableList[Field[Any, Any]]: ... def get_field(self, field_name: str) -> Field[Any, Any] | ForeignObjectRel | GenericForeignKey: ... From be19241720d2463e3632b45e3c541f26ea2b6a53 Mon Sep 17 00:00:00 2001 From: Christian Bundy Date: Mon, 23 Jan 2023 22:36:27 -0800 Subject: [PATCH 22/36] Fix ForeignKey --- django-stubs/contrib/admin/models.pyi | 4 ++-- django-stubs/contrib/admin/options.pyi | 2 +- django-stubs/contrib/redirects/models.pyi | 4 +++- django-stubs/core/serializers/base.pyi | 2 +- django-stubs/db/models/fields/related_descriptors.pyi | 6 +++--- django-stubs/db/models/fields/reverse_related.pyi | 4 ++-- django-stubs/forms/models.pyi | 6 +++--- 7 files changed, 15 insertions(+), 13 deletions(-) diff --git a/django-stubs/contrib/admin/models.pyi b/django-stubs/contrib/admin/models.pyi index 3657b5710..3e8366ebd 100644 --- a/django-stubs/contrib/admin/models.pyi +++ b/django-stubs/contrib/admin/models.pyi @@ -22,8 +22,8 @@ class LogEntryManager(models.Manager[LogEntry]): class LogEntry(models.Model): action_time: models.DateTimeField - user: models.ForeignKey - content_type: models.ForeignKey + user: models.ForeignKey[Any, Any] + content_type: models.ForeignKey[Any, Any] object_id: models.TextField object_repr: models.CharField action_flag: models.PositiveSmallIntegerField diff --git a/django-stubs/contrib/admin/options.pyi b/django-stubs/contrib/admin/options.pyi index 87a9f8211..3a2dde5d1 100644 --- a/django-stubs/contrib/admin/options.pyi +++ b/django-stubs/contrib/admin/options.pyi @@ -109,7 +109,7 @@ class BaseModelAdmin(Generic[_ModelT]): self, db: str | None, db_field: RelatedField, request: HttpRequest ) -> QuerySet[Model] | None: ... def formfield_for_foreignkey( - self, db_field: ForeignKey, request: HttpRequest, **kwargs: Any + self, db_field: ForeignKey[Any, Any], request: HttpRequest, **kwargs: Any ) -> ModelChoiceField: ... def formfield_for_manytomany( self, db_field: ManyToManyField, request: HttpRequest, **kwargs: Any diff --git a/django-stubs/contrib/redirects/models.pyi b/django-stubs/contrib/redirects/models.pyi index 444960881..59b87e6e4 100644 --- a/django-stubs/contrib/redirects/models.pyi +++ b/django-stubs/contrib/redirects/models.pyi @@ -1,6 +1,8 @@ +from typing import Any + from django.db import models class Redirect(models.Model): - site: models.ForeignKey + site: models.ForeignKey[Any, Any] old_path: models.CharField new_path: models.CharField diff --git a/django-stubs/core/serializers/base.pyi b/django-stubs/core/serializers/base.pyi index 5931ca35e..8d20e2112 100644 --- a/django-stubs/core/serializers/base.pyi +++ b/django-stubs/core/serializers/base.pyi @@ -85,5 +85,5 @@ def deserialize_m2m_values( field: ManyToManyField, field_value: Iterable[Any], using: str | None, handle_forward_references: bool ) -> Sequence[Any] | object: ... def deserialize_fk_value( - field: ForeignKey, field_value: Any, using: str | None, handle_forward_references: bool + field: ForeignKey[Any, Any], field_value: Any, using: str | None, handle_forward_references: bool ) -> Any | object: ... diff --git a/django-stubs/db/models/fields/related_descriptors.pyi b/django-stubs/db/models/fields/related_descriptors.pyi index 254740423..424eb4dae 100644 --- a/django-stubs/db/models/fields/related_descriptors.pyi +++ b/django-stubs/db/models/fields/related_descriptors.pyi @@ -17,8 +17,8 @@ class ForeignKeyDeferredAttribute(DeferredAttribute): field: RelatedField class ForwardManyToOneDescriptor: - field: ForeignKey - def __init__(self, field_with_rel: ForeignKey) -> None: ... + field: ForeignKey[Any, Any] + def __init__(self, field_with_rel: ForeignKey[Any, Any]) -> None: ... @property def RelatedObjectDoesNotExist(self) -> type[ObjectDoesNotExist]: ... def is_cached(self, instance: Model) -> bool: ... @@ -53,7 +53,7 @@ class ReverseOneToOneDescriptor: class ReverseManyToOneDescriptor: rel: ManyToOneRel - field: ForeignKey + field: ForeignKey[Any, Any] def __init__(self, rel: ManyToOneRel) -> None: ... @property def related_manager_cls(self) -> type[RelatedManager]: ... diff --git a/django-stubs/db/models/fields/reverse_related.pyi b/django-stubs/db/models/fields/reverse_related.pyi index 9bfda9b9f..e7259b890 100644 --- a/django-stubs/db/models/fields/reverse_related.pyi +++ b/django-stubs/db/models/fields/reverse_related.pyi @@ -84,10 +84,10 @@ class ForeignObjectRel(FieldCacheMixin): def get_path_info(self, filtered_relation: FilteredRelation | None = ...) -> list[PathInfo]: ... class ManyToOneRel(ForeignObjectRel): - field: ForeignKey + field: ForeignKey[Any, Any] def __init__( self, - field: ForeignKey, + field: ForeignKey[Any, Any], to: type[Model] | str, field_name: str, related_name: str | None = ..., diff --git a/django-stubs/forms/models.pyi b/django-stubs/forms/models.pyi index bd5babbc3..70c3675e3 100644 --- a/django-stubs/forms/models.pyi +++ b/django-stubs/forms/models.pyi @@ -177,7 +177,7 @@ class BaseInlineFormSet(Generic[_M, _ParentM, _ModelFormT], BaseModelFormSet[_M, instance: _ParentM save_as_new: bool unique_fields: Collection[str] - fk: ForeignKey # set by inlineformset_set + fk: ForeignKey[Any, Any] # set by inlineformset_set def __init__( self, data: _DataT | None = ..., @@ -312,8 +312,8 @@ def modelform_defines_fields(form_class: type[ModelForm[Model]]) -> bool: ... @overload def _get_foreign_key( # type: ignore parent_model: type[Model], model: type[Model], fk_name: str | None = ..., can_fail: Literal[True] = ... -) -> ForeignKey | None: ... +) -> ForeignKey[Any, Any] | None: ... @overload def _get_foreign_key( parent_model: type[Model], model: type[Model], fk_name: str | None = ..., can_fail: Literal[False] = ... -) -> ForeignKey: ... +) -> ForeignKey[Any, Any]: ... From 16db65772506e2eefc942216c8a3fd7928825712 Mon Sep 17 00:00:00 2001 From: Christian Bundy Date: Mon, 23 Jan 2023 22:38:59 -0800 Subject: [PATCH 23/36] Fix CharField --- django-stubs/contrib/admin/models.pyi | 2 +- django-stubs/contrib/contenttypes/models.pyi | 4 ++-- django-stubs/contrib/flatpages/models.pyi | 8 +++++--- django-stubs/contrib/postgres/fields/citext.pyi | 4 +++- django-stubs/contrib/redirects/models.pyi | 4 ++-- django-stubs/db/models/functions/text.pyi | 8 ++++---- 6 files changed, 17 insertions(+), 13 deletions(-) diff --git a/django-stubs/contrib/admin/models.pyi b/django-stubs/contrib/admin/models.pyi index 3e8366ebd..9c271cde1 100644 --- a/django-stubs/contrib/admin/models.pyi +++ b/django-stubs/contrib/admin/models.pyi @@ -25,7 +25,7 @@ class LogEntry(models.Model): user: models.ForeignKey[Any, Any] content_type: models.ForeignKey[Any, Any] object_id: models.TextField - object_repr: models.CharField + object_repr: models.CharField[Any, Any] action_flag: models.PositiveSmallIntegerField change_message: models.TextField objects: LogEntryManager diff --git a/django-stubs/contrib/contenttypes/models.pyi b/django-stubs/contrib/contenttypes/models.pyi index 27034a696..4566f3897 100644 --- a/django-stubs/contrib/contenttypes/models.pyi +++ b/django-stubs/contrib/contenttypes/models.pyi @@ -13,8 +13,8 @@ class ContentTypeManager(models.Manager[ContentType]): class ContentType(models.Model): id: int - app_label: models.CharField - model: models.CharField + app_label: models.CharField[Any, Any] + model: models.CharField[Any, Any] objects: ContentTypeManager @property def name(self) -> str: ... diff --git a/django-stubs/contrib/flatpages/models.pyi b/django-stubs/contrib/flatpages/models.pyi index 4b578fe03..4c8d42540 100644 --- a/django-stubs/contrib/flatpages/models.pyi +++ b/django-stubs/contrib/flatpages/models.pyi @@ -1,12 +1,14 @@ +from typing import Any + from django.contrib.sites.models import Site from django.db import models class FlatPage(models.Model): - url: models.CharField - title: models.CharField + url: models.CharField[Any, Any] + title: models.CharField[Any, Any] content: models.TextField enable_comments: models.BooleanField - template_name: models.CharField + template_name: models.CharField[Any, Any] registration_required: models.BooleanField sites: models.ManyToManyField[Site, Site] def get_absolute_url(self) -> str: ... diff --git a/django-stubs/contrib/postgres/fields/citext.pyi b/django-stubs/contrib/postgres/fields/citext.pyi index e0fbfcb5b..c54b1087d 100644 --- a/django-stubs/contrib/postgres/fields/citext.pyi +++ b/django-stubs/contrib/postgres/fields/citext.pyi @@ -1,6 +1,8 @@ +from typing import Any + from django.db.models.fields import CharField, EmailField, TextField class CIText: ... -class CICharField(CIText, CharField): ... +class CICharField(CIText, CharField[Any, Any]): ... class CIEmailField(CIText, EmailField): ... class CITextField(CIText, TextField): ... diff --git a/django-stubs/contrib/redirects/models.pyi b/django-stubs/contrib/redirects/models.pyi index 59b87e6e4..199537af7 100644 --- a/django-stubs/contrib/redirects/models.pyi +++ b/django-stubs/contrib/redirects/models.pyi @@ -4,5 +4,5 @@ from django.db import models class Redirect(models.Model): site: models.ForeignKey[Any, Any] - old_path: models.CharField - new_path: models.CharField + old_path: models.CharField[Any, Any] + new_path: models.CharField[Any, Any] diff --git a/django-stubs/db/models/functions/text.pyi b/django-stubs/db/models/functions/text.pyi index dedbf6971..9c146674c 100644 --- a/django-stubs/db/models/functions/text.pyi +++ b/django-stubs/db/models/functions/text.pyi @@ -33,7 +33,7 @@ class Concat(Func): def __init__(self, *expressions: Any, **extra: Any) -> None: ... class Left(Func): - output_field: models.CharField + output_field: models.CharField[Any, Any] def __init__(self, expression: Expression | str, length: Expression | int, **extra: Any) -> None: ... def get_substr(self) -> Substr: ... def as_oracle(self, compiler: SQLCompiler, connection: BaseDatabaseWrapper, **extra_context: Any) -> _AsSqlType: ... @@ -46,7 +46,7 @@ class Length(Transform): class Lower(Transform): ... class LPad(Func): - output_field: models.CharField + output_field: models.CharField[Any, Any] def __init__( self, expression: Expression | str, length: Expression | int | None, fill_text: Expression = ..., **extra: Any ) -> None: ... @@ -59,7 +59,7 @@ class Ord(Transform): def as_mysql(self, compiler: SQLCompiler, connection: BaseDatabaseWrapper, **extra_context: Any) -> _AsSqlType: ... class Repeat(Func): - output_field: models.CharField + output_field: models.CharField[Any, Any] def __init__(self, expression: Expression | str, number: Expression | int | None, **extra: Any) -> None: ... def as_oracle(self, compiler: SQLCompiler, connection: BaseDatabaseWrapper, **extra_context: Any) -> _AsSqlType: ... @@ -90,7 +90,7 @@ class StrIndex(Func): ) -> _AsSqlType: ... class Substr(Func): - output_field: models.CharField + output_field: models.CharField[Any, Any] def __init__( self, expression: Expression | str, pos: Expression | int, length: Expression | int | None = ..., **extra: Any ) -> None: ... From 4c7f50620a1b3b987d54026e916e3e3c9fb20d0e Mon Sep 17 00:00:00 2001 From: Christian Bundy Date: Mon, 23 Jan 2023 22:40:59 -0800 Subject: [PATCH 24/36] Fix Lookup --- django-stubs/contrib/gis/db/models/lookups.pyi | 2 +- django-stubs/contrib/postgres/search.pyi | 2 +- django-stubs/db/models/expressions.pyi | 2 +- django-stubs/db/models/fields/related_lookups.pyi | 2 +- django-stubs/db/models/fields/reverse_related.pyi | 2 +- django-stubs/db/models/lookups.pyi | 4 ++-- django-stubs/db/models/query_utils.pyi | 4 ++-- django-stubs/db/models/sql/query.pyi | 2 +- django-stubs/test/utils.pyi | 2 +- 9 files changed, 11 insertions(+), 11 deletions(-) diff --git a/django-stubs/contrib/gis/db/models/lookups.pyi b/django-stubs/contrib/gis/db/models/lookups.pyi index 6929e6e08..2ce50ef32 100644 --- a/django-stubs/contrib/gis/db/models/lookups.pyi +++ b/django-stubs/contrib/gis/db/models/lookups.pyi @@ -4,7 +4,7 @@ from django.db.models import Lookup, Transform class RasterBandTransform(Transform): ... -class GISLookup(Lookup): +class GISLookup(Lookup[Any]): sql_template: Any transform_func: Any distance: bool diff --git a/django-stubs/contrib/postgres/search.pyi b/django-stubs/contrib/postgres/search.pyi index 2746caa96..35ac9f6cb 100644 --- a/django-stubs/contrib/postgres/search.pyi +++ b/django-stubs/contrib/postgres/search.pyi @@ -8,7 +8,7 @@ from typing_extensions import TypeAlias _Expression: TypeAlias = str | Combinable | SearchQueryCombinable -class SearchVectorExact(Lookup): ... +class SearchVectorExact(Lookup[Any]): ... class SearchVectorField(Field[Any, Any]): ... class SearchQueryField(Field[Any, Any]): ... diff --git a/django-stubs/db/models/expressions.pyi b/django-stubs/db/models/expressions.pyi index de1584f49..c455505be 100644 --- a/django-stubs/db/models/expressions.pyi +++ b/django-stubs/db/models/expressions.pyi @@ -83,7 +83,7 @@ class BaseExpression: def output_field(self) -> Field[Any, Any]: ... @property def convert_value(self) -> Callable[..., Any]: ... - def get_lookup(self, lookup: str) -> type[Lookup] | None: ... + def get_lookup(self, lookup: str) -> type[Lookup[Any]] | None: ... def get_transform(self, name: str) -> type[Transform] | None: ... def relabeled_clone(self: Self, change_map: dict[str | None, str]) -> Self: ... def copy(self: Self) -> Self: ... diff --git a/django-stubs/db/models/fields/related_lookups.pyi b/django-stubs/db/models/fields/related_lookups.pyi index ea06f5ab6..6df8480c9 100644 --- a/django-stubs/db/models/fields/related_lookups.pyi +++ b/django-stubs/db/models/fields/related_lookups.pyi @@ -28,7 +28,7 @@ class MultiColSource: field: Field[Any, Any], ) -> None: ... def relabeled_clone(self, relabels: Mapping[str, str]) -> MultiColSource: ... - def get_lookup(self, lookup: str) -> type[Lookup] | None: ... + def get_lookup(self, lookup: str) -> type[Lookup[Any]] | None: ... def get_normalized_value(value: Any, lhs: Any) -> tuple[Any, ...]: ... diff --git a/django-stubs/db/models/fields/reverse_related.pyi b/django-stubs/db/models/fields/reverse_related.pyi index e7259b890..8d1588960 100644 --- a/django-stubs/db/models/fields/reverse_related.pyi +++ b/django-stubs/db/models/fields/reverse_related.pyi @@ -61,7 +61,7 @@ class ForeignObjectRel(FieldCacheMixin): def one_to_many(self) -> bool: ... @property def one_to_one(self) -> bool: ... - def get_lookup(self, lookup_name: str) -> type[Lookup] | None: ... + def get_lookup(self, lookup_name: str) -> type[Lookup[Any]] | None: ... def get_internal_type(self) -> str: ... @property def db_type(self) -> Any: ... diff --git a/django-stubs/db/models/lookups.pyi b/django-stubs/db/models/lookups.pyi index 25a82aa43..03e743031 100644 --- a/django-stubs/db/models/lookups.pyi +++ b/django-stubs/db/models/lookups.pyi @@ -43,7 +43,7 @@ class Lookup(Generic[_T]): @property def is_summary(self) -> bool: ... @property - def identity(self) -> tuple[type[Lookup], Any, Any]: ... + def identity(self) -> tuple[type[Lookup[Any]], Any, Any]: ... class Transform(RegisterLookupMixin, Func): bilateral: bool @@ -103,7 +103,7 @@ class IsNull(BuiltinLookup[bool]): ... class Regex(BuiltinLookup[str]): ... class IRegex(Regex): ... -class YearLookup(Lookup): +class YearLookup(Lookup[Any]): def year_lookup_bounds(self, connection: BaseDatabaseWrapper, year: int) -> list[str]: ... def get_direct_rhs_sql(self, connection: BaseDatabaseWrapper, rhs: str) -> str: ... def get_bound_params(self, start: Any, finish: Any) -> Any: ... diff --git a/django-stubs/db/models/query_utils.pyi b/django-stubs/db/models/query_utils.pyi index 5274fd4ed..552467cc0 100644 --- a/django-stubs/db/models/query_utils.pyi +++ b/django-stubs/db/models/query_utils.pyi @@ -55,14 +55,14 @@ class RegisterLookupMixin: lookup_name: str @classmethod def get_lookups(cls) -> dict[str, Any]: ... - def get_lookup(self, lookup_name: str) -> type[Lookup] | None: ... + def get_lookup(self, lookup_name: str) -> type[Lookup[Any]] | None: ... def get_transform(self, lookup_name: str) -> type[Transform] | None: ... @staticmethod def merge_dicts(dicts: Iterable[dict[str, Any]]) -> dict[str, Any]: ... @classmethod def register_lookup(cls, lookup: _R, lookup_name: str | None = ...) -> _R: ... @classmethod - def _unregister_lookup(cls, lookup: type[Lookup], lookup_name: str | None = ...) -> None: ... + def _unregister_lookup(cls, lookup: type[Lookup[Any]], lookup_name: str | None = ...) -> None: ... def select_related_descend( field: Field[Any, Any], diff --git a/django-stubs/db/models/sql/query.pyi b/django-stubs/db/models/sql/query.pyi index a73c25e72..aca11ca3d 100644 --- a/django-stubs/db/models/sql/query.pyi +++ b/django-stubs/db/models/sql/query.pyi @@ -195,7 +195,7 @@ class Query(BaseExpression): def trim_start(self, names_with_path: list[tuple[str, list[PathInfo]]]) -> tuple[str, bool]: ... def is_nullable(self, field: Field[Any, Any]) -> bool: ... def check_filterable(self, expression: Any) -> None: ... - def build_lookup(self, lookups: Sequence[str], lhs: Expression | Query, rhs: Any) -> Lookup: ... + def build_lookup(self, lookups: Sequence[str], lhs: Expression | Query, rhs: Any) -> Lookup[Any]: ... def try_transform(self, lhs: Expression | Query, name: str) -> Transform: ... class JoinPromoter: diff --git a/django-stubs/test/utils.pyi b/django-stubs/test/utils.pyi index 1aff4cb38..548f8cd80 100644 --- a/django-stubs/test/utils.pyi +++ b/django-stubs/test/utils.pyi @@ -173,5 +173,5 @@ def teardown_databases( def require_jinja2(test_func: _C) -> _C: ... @contextmanager def register_lookup( - field: type[RegisterLookupMixin], *lookups: type[Lookup | Transform], lookup_name: str | None = ... + field: type[RegisterLookupMixin], *lookups: type[Lookup[Any] | Transform], lookup_name: str | None = ... ) -> Iterator[None]: ... From faa78851505f09bdb73e187fd81c50a939392ddf Mon Sep 17 00:00:00 2001 From: Christian Bundy Date: Mon, 23 Jan 2023 22:47:51 -0800 Subject: [PATCH 25/36] Fix UploadedFile --- django-stubs/core/files/uploadedfile.pyi | 4 ++-- django-stubs/core/files/uploadhandler.pyi | 13 +++++++------ django-stubs/forms/utils.pyi | 5 +++-- django-stubs/http/request.pyi | 8 ++++---- 4 files changed, 16 insertions(+), 14 deletions(-) diff --git a/django-stubs/core/files/uploadedfile.pyi b/django-stubs/core/files/uploadedfile.pyi index e62699f4c..8a54c3c75 100644 --- a/django-stubs/core/files/uploadedfile.pyi +++ b/django-stubs/core/files/uploadedfile.pyi @@ -19,7 +19,7 @@ class UploadedFile(File[AnyStr]): content_type_extra: dict[str, str] | None = ..., ) -> None: ... -class TemporaryUploadedFile(UploadedFile): +class TemporaryUploadedFile(UploadedFile[AnyStr]): def __init__( self, name: str, @@ -30,7 +30,7 @@ class TemporaryUploadedFile(UploadedFile): ) -> None: ... def temporary_file_path(self) -> str: ... -class InMemoryUploadedFile(UploadedFile): +class InMemoryUploadedFile(UploadedFile[AnyStr]): field_name: str | None def __init__( self, diff --git a/django-stubs/core/files/uploadhandler.pyi b/django-stubs/core/files/uploadhandler.pyi index 1135d0215..4ea4351fb 100644 --- a/django-stubs/core/files/uploadhandler.pyi +++ b/django-stubs/core/files/uploadhandler.pyi @@ -1,7 +1,8 @@ # Stubs for django.core.files.uploadhandler (Python 3.5) -from typing import IO, Any +from typing import IO, Any, AnyStr +from django.core.files import File from django.core.files.uploadedfile import TemporaryUploadedFile, UploadedFile from django.http.request import HttpRequest, QueryDict from django.utils.datastructures import MultiValueDict @@ -32,7 +33,7 @@ class FileUploadHandler: content_length: int, boundary: str, encoding: str | None = ..., - ) -> tuple[QueryDict, MultiValueDict[str, UploadedFile]] | None: ... + ) -> tuple[QueryDict, MultiValueDict[str, UploadedFile[AnyStr]]] | None: ... def new_file( self, field_name: str, @@ -43,7 +44,7 @@ class FileUploadHandler: content_type_extra: dict[str, str] | None = ..., ) -> None: ... def receive_data_chunk(self, raw_data: bytes, start: int) -> bytes | None: ... - def file_complete(self, file_size: int) -> UploadedFile | None: ... + def file_complete(self, file_size: int) -> UploadedFile[AnyStr] | None: ... def upload_complete(self) -> None: ... def upload_interrupted(self) -> None: ... @@ -59,7 +60,7 @@ class TemporaryFileUploadHandler(FileUploadHandler): content_type_extra: dict[str, str] | None = ..., ) -> None: ... def receive_data_chunk(self, raw_data: bytes, start: int) -> bytes | None: ... - def file_complete(self, file_size: int) -> UploadedFile | None: ... + def file_complete(self, file_size: int) -> UploadedFile[AnyStr] | None: ... def upload_interrupted(self) -> None: ... class MemoryFileUploadHandler(FileUploadHandler): @@ -72,7 +73,7 @@ class MemoryFileUploadHandler(FileUploadHandler): content_length: int, boundary: str, encoding: str | None = ..., - ) -> tuple[QueryDict, MultiValueDict[str, UploadedFile]] | None: ... + ) -> tuple[QueryDict, MultiValueDict[str, UploadedFile[AnyStr]]] | None: ... def new_file( self, field_name: str, @@ -83,6 +84,6 @@ class MemoryFileUploadHandler(FileUploadHandler): content_type_extra: dict[str, str] | None = ..., ) -> None: ... def receive_data_chunk(self, raw_data: bytes, start: int) -> bytes | None: ... - def file_complete(self, file_size: int) -> UploadedFile | None: ... + def file_complete(self, file_size: int) -> UploadedFile[AnyStr] | None: ... def load_handler(path: str, *args: Any, **kwargs: Any) -> FileUploadHandler: ... diff --git a/django-stubs/forms/utils.pyi b/django-stubs/forms/utils.pyi index cbcfe7abf..4ff83bc2a 100644 --- a/django-stubs/forms/utils.pyi +++ b/django-stubs/forms/utils.pyi @@ -1,9 +1,10 @@ from collections import UserList from collections.abc import Mapping, Sequence from datetime import datetime -from typing import Any +from typing import Any, AnyStr from django.core.exceptions import ValidationError +from django.core.files import File from django.core.files.uploadedfile import UploadedFile from django.utils.datastructures import MultiValueDict from django.utils.safestring import SafeString @@ -11,7 +12,7 @@ from typing_extensions import TypeAlias _DataT: TypeAlias = Mapping[str, Any] # noqa: Y047 -_FilesT: TypeAlias = MultiValueDict[str, UploadedFile] # noqa: Y047 +_FilesT: TypeAlias = MultiValueDict[str, UploadedFile[AnyStr]] # noqa: Y047 def pretty_name(name: str) -> str: ... def flatatt(attrs: dict[str, Any]) -> SafeString: ... diff --git a/django-stubs/http/request.pyi b/django-stubs/http/request.pyi index 690615a20..fa1044471 100644 --- a/django-stubs/http/request.pyi +++ b/django-stubs/http/request.pyi @@ -1,14 +1,14 @@ from collections.abc import Iterable, Mapping from io import BytesIO from re import Pattern -from typing import Any, BinaryIO, NoReturn, TypeVar, overload +from typing import Any, AnyStr, BinaryIO, NoReturn, TypeVar, overload from _typeshed import Self from django.contrib.auth.base_user import AbstractBaseUser from django.contrib.auth.models import AnonymousUser from django.contrib.sessions.backends.base import SessionBase from django.contrib.sites.models import Site -from django.core.files import uploadedfile, uploadhandler +from django.core.files import File, uploadedfile, uploadhandler from django.urls import ResolverMatch from django.utils.datastructures import CaseInsensitiveMapping, ImmutableList, MultiValueDict from typing_extensions import Literal, TypeAlias @@ -33,7 +33,7 @@ class HttpRequest(BytesIO): POST: _ImmutableQueryDict COOKIES: dict[str, str] META: dict[str, Any] - FILES: MultiValueDict[str, uploadedfile.UploadedFile] + FILES: MultiValueDict[str, uploadedfile.UploadedFile[AnyStr]] path: str path_info: str method: str | None @@ -86,7 +86,7 @@ class HttpRequest(BytesIO): def accepted_types(self) -> list[MediaType]: ... def parse_file_upload( self, META: Mapping[str, Any], post_data: BinaryIO - ) -> tuple[QueryDict, MultiValueDict[str, uploadedfile.UploadedFile]]: ... + ) -> tuple[QueryDict, MultiValueDict[str, uploadedfile.UploadedFile[AnyStr]]]: ... @property def headers(self) -> HttpHeaders: ... @property From 99dc74d93d9f27a42fbbeb39510fcaa25981e2a4 Mon Sep 17 00:00:00 2001 From: Christian Bundy Date: Mon, 23 Jan 2023 22:54:20 -0800 Subject: [PATCH 26/36] Fix IntegerField --- .../contrib/admin/templatetags/admin_urls.pyi | 5 ++-- django-stubs/contrib/admin/utils.pyi | 4 +-- django-stubs/contrib/admin/views/main.pyi | 4 +-- django-stubs/contrib/auth/__init__.pyi | 3 +- django-stubs/contrib/postgres/forms/array.pyi | 6 ++-- django-stubs/db/models/deletion.pyi | 2 +- django-stubs/db/models/fields/proxy.pyi | 2 +- django-stubs/db/models/functions/datetime.pyi | 2 +- django-stubs/db/models/functions/text.pyi | 6 ++-- django-stubs/db/models/functions/window.pyi | 8 ++--- django-stubs/db/models/sql/query.pyi | 2 +- django-stubs/forms/forms.pyi | 6 ++-- django-stubs/forms/formsets.pyi | 6 ++-- django-stubs/forms/models.pyi | 7 +++-- django-stubs/forms/widgets.pyi | 30 +++++++++---------- 15 files changed, 48 insertions(+), 45 deletions(-) diff --git a/django-stubs/contrib/admin/templatetags/admin_urls.pyi b/django-stubs/contrib/admin/templatetags/admin_urls.pyi index 02b0351be..2977856dc 100644 --- a/django-stubs/contrib/admin/templatetags/admin_urls.pyi +++ b/django-stubs/contrib/admin/templatetags/admin_urls.pyi @@ -1,16 +1,17 @@ from typing import Any from uuid import UUID +from django.db.models import Model from django.db.models.options import Options from django.template.context import RequestContext from django.utils.safestring import SafeString register: Any -def admin_urlname(value: Options, arg: SafeString) -> str: ... +def admin_urlname(value: Options[Model], arg: SafeString) -> str: ... def admin_urlquote(value: int | str | UUID) -> int | str | UUID: ... def add_preserved_filters( - context: dict[str, Options | str] | RequestContext, + context: dict[str, Options[Model] | str] | RequestContext, url: str, popup: bool = ..., to_field: str | None = ..., diff --git a/django-stubs/contrib/admin/utils.pyi b/django-stubs/contrib/admin/utils.pyi index f3e8c8c7c..bf06d9fd6 100644 --- a/django-stubs/contrib/admin/utils.pyi +++ b/django-stubs/contrib/admin/utils.pyi @@ -19,7 +19,7 @@ from typing_extensions import Literal, TypedDict class FieldIsAForeignKeyColumnName(Exception): ... -def lookup_needs_distinct(opts: Options, lookup_path: str) -> bool: ... +def lookup_needs_distinct(opts: Options[Model], lookup_path: str) -> bool: ... def prepare_lookup_value(key: str, value: datetime.datetime | str) -> bool | datetime.datetime | str: ... def quote(s: int | str | UUID) -> str: ... def unquote(s: str) -> str: ... @@ -51,7 +51,7 @@ class _ModelFormatDict(TypedDict): verbose_name_plural: str def model_format_dict(obj: Model | type[Model] | QuerySet[Model] | Options[Model]) -> _ModelFormatDict: ... -def model_ngettext(obj: Options | QuerySet[Model], n: int | None = ...) -> str: ... +def model_ngettext(obj: Options[Model] | QuerySet[Model], n: int | None = ...) -> str: ... def lookup_field( name: Callable[..., Any] | str, obj: Model, model_admin: BaseModelAdmin | None = ... ) -> tuple[Field[Any, Any] | None, str | None, Any]: ... diff --git a/django-stubs/contrib/admin/views/main.pyi b/django-stubs/contrib/admin/views/main.pyi index be18482f0..2f8012c41 100644 --- a/django-stubs/contrib/admin/views/main.pyi +++ b/django-stubs/contrib/admin/views/main.pyi @@ -23,8 +23,8 @@ IGNORED_PARAMS: tuple[str, ...] class ChangeList: model: type[Model] - opts: Options - lookup_opts: Options + opts: Options[Model] + lookup_opts: Options[Model] root_queryset: QuerySet[Model] list_display: _DisplayT list_display_links: _DisplayT diff --git a/django-stubs/contrib/auth/__init__.pyi b/django-stubs/contrib/auth/__init__.pyi index 0d24bb9b0..5ae099ffb 100644 --- a/django-stubs/contrib/auth/__init__.pyi +++ b/django-stubs/contrib/auth/__init__.pyi @@ -7,6 +7,7 @@ from django.db.models.options import Options from django.http.request import HttpRequest from django.test.client import Client +from ..db.models import Model from .signals import user_logged_in as user_logged_in from .signals import user_logged_out as user_logged_out from .signals import user_login_failed as user_login_failed @@ -25,7 +26,7 @@ def login( def logout(request: HttpRequest) -> None: ... def get_user_model() -> type[AbstractBaseUser]: ... def get_user(request: HttpRequest | Client) -> AbstractBaseUser | AnonymousUser: ... -def get_permission_codename(action: str, opts: Options) -> str: ... +def get_permission_codename(action: str, opts: Options[Model]) -> str: ... def update_session_auth_hash(request: HttpRequest, user: AbstractBaseUser) -> None: ... default_app_config: str diff --git a/django-stubs/contrib/postgres/forms/array.pyi b/django-stubs/contrib/postgres/forms/array.pyi index 4ba068404..8f340c134 100644 --- a/django-stubs/contrib/postgres/forms/array.pyi +++ b/django-stubs/contrib/postgres/forms/array.pyi @@ -1,5 +1,5 @@ from collections.abc import Sequence -from typing import Any +from typing import Any, AnyStr from django import forms as forms from django.contrib.postgres.validators import ArrayMaxLengthValidator as ArrayMaxLengthValidator @@ -41,8 +41,8 @@ class SplitArrayWidget(forms.Widget): def __init__(self, widget: forms.Widget | type[forms.Widget], size: int, **kwargs: Any) -> None: ... @property def is_hidden(self) -> bool: ... - def value_from_datadict(self, data: _DataT, files: _FilesT, name: str) -> Any: ... - def value_omitted_from_data(self, data: _DataT, files: _FilesT, name: str) -> bool: ... + def value_from_datadict(self, data: _DataT, files: _FilesT[AnyStr], name: str) -> Any: ... + def value_omitted_from_data(self, data: _DataT, files: _FilesT[AnyStr], name: str) -> bool: ... def id_for_label(self, id_: str) -> str: ... def get_context(self, name: str, value: Any, attrs: _OptAttrs | None = ...) -> dict[str, Any]: ... @property diff --git a/django-stubs/db/models/deletion.pyi b/django-stubs/db/models/deletion.pyi index 700b353eb..f5002f348 100644 --- a/django-stubs/db/models/deletion.pyi +++ b/django-stubs/db/models/deletion.pyi @@ -45,7 +45,7 @@ def RESTRICT( using: str, ) -> None: ... def SET(value: Any) -> Callable[..., Any]: ... -def get_candidate_relations_to_delete(opts: Options) -> Iterable[Field[Any, Any]]: ... +def get_candidate_relations_to_delete(opts: Options[Model]) -> Iterable[Field[Any, Any]]: ... class ProtectedError(IntegrityError): protected_objects: set[Model] diff --git a/django-stubs/db/models/fields/proxy.pyi b/django-stubs/db/models/fields/proxy.pyi index ef647530a..0bbe0e28b 100644 --- a/django-stubs/db/models/fields/proxy.pyi +++ b/django-stubs/db/models/fields/proxy.pyi @@ -2,5 +2,5 @@ from typing import Any from django.db.models import fields -class OrderWrt(fields.IntegerField): +class OrderWrt(fields.IntegerField[Any, Any]): def __init__(self, *args: Any, **kwargs: Any) -> None: ... diff --git a/django-stubs/db/models/functions/datetime.pyi b/django-stubs/db/models/functions/datetime.pyi index e5ce958ae..a2713ed9b 100644 --- a/django-stubs/db/models/functions/datetime.pyi +++ b/django-stubs/db/models/functions/datetime.pyi @@ -9,7 +9,7 @@ class TimezoneMixin: class Extract(TimezoneMixin, Transform): lookup_name: str - output_field: models.IntegerField + output_field: models.IntegerField[Any, Any] def __init__( self, expression: Any, lookup_name: str | None = ..., tzinfo: Any | None = ..., **extra: Any ) -> None: ... diff --git a/django-stubs/db/models/functions/text.pyi b/django-stubs/db/models/functions/text.pyi index 9c146674c..cd9898ead 100644 --- a/django-stubs/db/models/functions/text.pyi +++ b/django-stubs/db/models/functions/text.pyi @@ -40,7 +40,7 @@ class Left(Func): def as_sqlite(self, compiler: SQLCompiler, connection: BaseDatabaseWrapper, **extra_context: Any) -> _AsSqlType: ... class Length(Transform): - output_field: models.IntegerField + output_field: models.IntegerField[Any, Any] def as_mysql(self, compiler: SQLCompiler, connection: BaseDatabaseWrapper, **extra_context: Any) -> _AsSqlType: ... class Lower(Transform): ... @@ -54,7 +54,7 @@ class LPad(Func): class LTrim(Transform): ... class Ord(Transform): - output_field: models.IntegerField + output_field: models.IntegerField[Any, Any] def as_sqlite(self, compiler: SQLCompiler, connection: BaseDatabaseWrapper, **extra_context: Any) -> _AsSqlType: ... def as_mysql(self, compiler: SQLCompiler, connection: BaseDatabaseWrapper, **extra_context: Any) -> _AsSqlType: ... @@ -84,7 +84,7 @@ class SHA384(MySQLSHA2Mixin, OracleHashMixin, PostgreSQLSHAMixin, Transform): .. class SHA512(MySQLSHA2Mixin, OracleHashMixin, PostgreSQLSHAMixin, Transform): ... class StrIndex(Func): - output_field: models.IntegerField + output_field: models.IntegerField[Any, Any] def as_postgresql( self, compiler: SQLCompiler, connection: BaseDatabaseWrapper, **extra_context: Any ) -> _AsSqlType: ... diff --git a/django-stubs/db/models/functions/window.pyi b/django-stubs/db/models/functions/window.pyi index 7de622d19..33e93d52e 100644 --- a/django-stubs/db/models/functions/window.pyi +++ b/django-stubs/db/models/functions/window.pyi @@ -7,7 +7,7 @@ class CumeDist(Func): output_field: models.FloatField class DenseRank(Func): - output_field: models.IntegerField + output_field: models.IntegerField[Any, Any] class FirstValue(Func): ... @@ -23,13 +23,13 @@ class NthValue(Func): class Ntile(Func): def __init__(self, num_buckets: int = ..., **extra: Any) -> None: ... - output_field: models.IntegerField + output_field: models.IntegerField[Any, Any] class PercentRank(Func): output_field: models.FloatField class Rank(Func): - output_field: models.IntegerField + output_field: models.IntegerField[Any, Any] class RowNumber(Func): - output_field: models.IntegerField + output_field: models.IntegerField[Any, Any] diff --git a/django-stubs/db/models/sql/query.pyi b/django-stubs/db/models/sql/query.pyi index aca11ca3d..09b74f139 100644 --- a/django-stubs/db/models/sql/query.pyi +++ b/django-stubs/db/models/sql/query.pyi @@ -90,7 +90,7 @@ class Query(BaseExpression): def sql_with_params(self) -> tuple[str, tuple[Any, ...]]: ... def __deepcopy__(self, memo: dict[int, Any]) -> Query: ... def get_compiler(self, using: str | None = ..., connection: BaseDatabaseWrapper | None = ...) -> SQLCompiler: ... - def get_meta(self) -> Options: ... + def get_meta(self) -> Options[Model]: ... def clone(self) -> Query: ... def chain(self, klass: type[Query] | None = ...) -> Query: ... def relabeled_clone(self, change_map: dict[str | None, str]) -> Query: ... diff --git a/django-stubs/forms/forms.pyi b/django-stubs/forms/forms.pyi index b061f78ee..9150e2ab3 100644 --- a/django-stubs/forms/forms.pyi +++ b/django-stubs/forms/forms.pyi @@ -1,5 +1,5 @@ from collections.abc import Iterable, Iterator, Mapping, Sequence -from typing import Any, ClassVar +from typing import Any, AnyStr, ClassVar from django.core.exceptions import ValidationError as ValidationError from django.forms.boundfield import BoundField @@ -20,7 +20,7 @@ class BaseForm: use_required_attribute: bool is_bound: bool data: _DataT - files: _FilesT + files: _FilesT[AnyStr] auto_id: bool | str initial: Mapping[str, Any] error_class: type[ErrorList] @@ -33,7 +33,7 @@ class BaseForm: def __init__( self, data: _DataT | None = ..., - files: _FilesT | None = ..., + files: _FilesT[AnyStr] | None = ..., auto_id: bool | str = ..., prefix: str | None = ..., initial: Mapping[str, Any] | None = ..., diff --git a/django-stubs/forms/formsets.pyi b/django-stubs/forms/formsets.pyi index 47c82bbca..c3b91a302 100644 --- a/django-stubs/forms/formsets.pyi +++ b/django-stubs/forms/formsets.pyi @@ -1,5 +1,5 @@ from collections.abc import Iterator, Mapping, Sequence, Sized -from typing import Any, Generic, TypeVar +from typing import Any, AnyStr, Generic, TypeVar from django.forms.forms import BaseForm, Form from django.forms.utils import ErrorList, _DataT, _FilesT @@ -39,7 +39,7 @@ class BaseFormSet(Generic[_F], Sized): prefix: str | None auto_id: str data: _DataT - files: _FilesT + files: _FilesT[AnyStr] initial: Sequence[Mapping[str, Any]] | None form_kwargs: dict[str, Any] error_class: type[ErrorList] @@ -47,7 +47,7 @@ class BaseFormSet(Generic[_F], Sized): def __init__( self, data: _DataT | None = ..., - files: _FilesT | None = ..., + files: _FilesT[AnyStr] | None = ..., auto_id: str = ..., prefix: str | None = ..., initial: Sequence[Mapping[str, Any]] | None = ..., diff --git a/django-stubs/forms/models.pyi b/django-stubs/forms/models.pyi index 70c3675e3..4b3e7036c 100644 --- a/django-stubs/forms/models.pyi +++ b/django-stubs/forms/models.pyi @@ -1,6 +1,7 @@ from collections.abc import Callable, Collection, Container, Iterator, Mapping, Sequence from typing import ( # noqa: Y037 # https://github.com/python/mypy/issues/12211 Any, + AnyStr, ClassVar, Generic, TypeVar, @@ -79,7 +80,7 @@ class BaseModelForm(Generic[_M], BaseForm): def __init__( self, data: _DataT | None = ..., - files: _FilesT | None = ..., + files: _FilesT[AnyStr] | None = ..., auto_id: bool | str = ..., prefix: str | None = ..., initial: Mapping[str, Any] | None = ..., @@ -121,7 +122,7 @@ class BaseModelFormSet(Generic[_M, _ModelFormT], BaseFormSet[_ModelFormT]): def __init__( self, data: _DataT | None = ..., - files: _FilesT | None = ..., + files: _FilesT[AnyStr] | None = ..., auto_id: str = ..., prefix: str | None = ..., queryset: QuerySet[_M] | None = ..., @@ -181,7 +182,7 @@ class BaseInlineFormSet(Generic[_M, _ParentM, _ModelFormT], BaseModelFormSet[_M, def __init__( self, data: _DataT | None = ..., - files: _FilesT | None = ..., + files: _FilesT[AnyStr] | None = ..., instance: _ParentM | None = ..., save_as_new: bool = ..., prefix: str | None = ..., diff --git a/django-stubs/forms/widgets.pyi b/django-stubs/forms/widgets.pyi index 7f30b45db..43156f5bf 100644 --- a/django-stubs/forms/widgets.pyi +++ b/django-stubs/forms/widgets.pyi @@ -51,8 +51,8 @@ class Widget(metaclass=MediaDefiningClass): self, name: str, value: Any, attrs: _OptAttrs | None = ..., renderer: BaseRenderer | None = ... ) -> SafeString: ... def build_attrs(self, base_attrs: _OptAttrs, extra_attrs: _OptAttrs | None = ...) -> dict[str, Any]: ... - def value_from_datadict(self, data: _DataT, files: _FilesT, name: str) -> Any: ... - def value_omitted_from_data(self, data: _DataT, files: _FilesT, name: str) -> bool: ... + def value_from_datadict(self, data: _DataT, files: _FilesT[AnyStr], name: str) -> Any: ... + def value_omitted_from_data(self, data: _DataT, files: _FilesT[AnyStr], name: str) -> bool: ... def id_for_label(self, id_: str) -> str: ... def use_required_attribute(self, initial: Any) -> bool: ... @@ -96,8 +96,8 @@ class FileInput(Input): template_name: str needs_multipart_form: bool def format_value(self, value: Any) -> None: ... - def value_from_datadict(self, data: _DataT, files: _FilesT, name: str) -> Any: ... - def value_omitted_from_data(self, data: _DataT, files: _FilesT, name: str) -> bool: ... + def value_from_datadict(self, data: _DataT, files: _FilesT[AnyStr], name: str) -> Any: ... + def value_omitted_from_data(self, data: _DataT, files: _FilesT[AnyStr], name: str) -> bool: ... def use_required_attribute(self, initial: Any) -> bool: ... FILE_INPUT_CONTRADICTION: object @@ -111,8 +111,8 @@ class ClearableFileInput(FileInput): def clear_checkbox_id(self, name: str) -> str: ... def is_initial(self, value: File[AnyStr] | str | None) -> bool: ... def get_context(self, name: str, value: Any, attrs: _OptAttrs | None) -> dict[str, Any]: ... - def value_from_datadict(self, data: _DataT, files: _FilesT, name: str) -> Any: ... - def value_omitted_from_data(self, data: _DataT, files: _FilesT, name: str) -> bool: ... + def value_from_datadict(self, data: _DataT, files: _FilesT[AnyStr], name: str) -> Any: ... + def value_omitted_from_data(self, data: _DataT, files: _FilesT[AnyStr], name: str) -> bool: ... class Textarea(Widget): template_name: str @@ -174,7 +174,7 @@ class ChoiceWidget(Widget): attrs: _OptAttrs | None = ..., ) -> dict[str, Any]: ... def id_for_label(self, id_: str, index: str = ...) -> str: ... - def value_from_datadict(self, data: _DataT, files: _FilesT, name: str) -> Any: ... + def value_from_datadict(self, data: _DataT, files: _FilesT[AnyStr], name: str) -> Any: ... def format_value(self, value: Any) -> list[str]: ... # type: ignore class Select(ChoiceWidget): @@ -190,12 +190,12 @@ class Select(ChoiceWidget): class NullBooleanSelect(Select): def __init__(self, attrs: _OptAttrs | None = ...) -> None: ... def format_value(self, value: Any) -> str: ... # type: ignore - def value_from_datadict(self, data: _DataT, files: _FilesT, name: str) -> bool | None: ... + def value_from_datadict(self, data: _DataT, files: _FilesT[AnyStr], name: str) -> bool | None: ... class SelectMultiple(Select): allow_multiple_selected: bool - def value_from_datadict(self, data: _DataT, files: _FilesT, name: str) -> Any: ... - def value_omitted_from_data(self, data: _DataT, files: _FilesT, name: str) -> bool: ... + def value_from_datadict(self, data: _DataT, files: _FilesT[AnyStr], name: str) -> Any: ... + def value_omitted_from_data(self, data: _DataT, files: _FilesT[AnyStr], name: str) -> bool: ... class RadioSelect(ChoiceWidget): can_add_related: bool @@ -209,7 +209,7 @@ class CheckboxSelectMultiple(ChoiceWidget): template_name: str option_template_name: str def use_required_attribute(self, initial: Any) -> bool: ... - def value_omitted_from_data(self, data: _DataT, files: _FilesT, name: str) -> bool: ... + def value_omitted_from_data(self, data: _DataT, files: _FilesT[AnyStr], name: str) -> bool: ... def id_for_label(self, id_: str, index: str | None = ...) -> str: ... class MultiWidget(Widget): @@ -224,8 +224,8 @@ class MultiWidget(Widget): def is_hidden(self) -> bool: ... def get_context(self, name: str, value: Any, attrs: _OptAttrs | None) -> dict[str, Any]: ... def id_for_label(self, id_: str) -> str: ... - def value_from_datadict(self, data: _DataT, files: _FilesT, name: str) -> list[Any]: ... - def value_omitted_from_data(self, data: _DataT, files: _FilesT, name: str) -> bool: ... + def value_from_datadict(self, data: _DataT, files: _FilesT[AnyStr], name: str) -> list[Any]: ... + def value_omitted_from_data(self, data: _DataT, files: _FilesT[AnyStr], name: str) -> bool: ... def decompress(self, value: Any) -> Any | None: ... media: _Getter[Media] @property @@ -280,5 +280,5 @@ class SelectDateWidget(Widget): def get_context(self, name: str, value: Any, attrs: _OptAttrs | None) -> dict[str, Any]: ... def format_value(self, value: Any) -> dict[str, str | int | None]: ... # type: ignore def id_for_label(self, id_: str) -> str: ... - def value_from_datadict(self, data: _DataT, files: _FilesT, name: str) -> str | None | Any: ... - def value_omitted_from_data(self, data: _DataT, files: _FilesT, name: str) -> bool: ... + def value_from_datadict(self, data: _DataT, files: _FilesT[AnyStr], name: str) -> str | None | Any: ... + def value_omitted_from_data(self, data: _DataT, files: _FilesT[AnyStr], name: str) -> bool: ... From 851f5fa0934008ce78a1b678e51a82ddf4122939 Mon Sep 17 00:00:00 2001 From: Christian Bundy Date: Mon, 23 Jan 2023 22:56:36 -0800 Subject: [PATCH 27/36] Fix _DisplayT --- django-stubs/contrib/admin/options.pyi | 8 ++++---- django-stubs/contrib/admin/views/main.pyi | 8 ++++---- 2 files changed, 8 insertions(+), 8 deletions(-) diff --git a/django-stubs/contrib/admin/options.pyi b/django-stubs/contrib/admin/options.pyi index 3a2dde5d1..04fd71c89 100644 --- a/django-stubs/contrib/admin/options.pyi +++ b/django-stubs/contrib/admin/options.pyi @@ -140,8 +140,8 @@ _ModelAdmin = TypeVar("_ModelAdmin", bound=ModelAdmin[Model]) _ActionCallable: TypeAlias = Callable[[_ModelAdmin, HttpRequest, QuerySet[_ModelT]], HttpResponseBase | None] class ModelAdmin(BaseModelAdmin[_ModelT]): - list_display: _DisplayT - list_display_links: _DisplayT | None + list_display: _DisplayT[_ModelT] + list_display_links: _DisplayT[_ModelT] | None list_filter: _ListOrTuple[_ListFilterT] list_select_related: bool | Sequence[str] list_per_page: int @@ -206,8 +206,8 @@ class ModelAdmin(BaseModelAdmin[_ModelT]): self, request: HttpRequest, default_choices: list[tuple[str, str]] = ... ) -> list[tuple[str, str]]: ... def get_action(self, action: Callable[..., Any] | str) -> tuple[Callable[..., str], str, str] | None: ... - def get_list_display(self, request: HttpRequest) -> _DisplayT: ... - def get_list_display_links(self, request: HttpRequest, list_display: _DisplayT) -> _DisplayT: ... + def get_list_display(self, request: HttpRequest) -> _DisplayT[_ModelT]: ... + def get_list_display_links(self, request: HttpRequest, list_display: _DisplayT[_ModelT]) -> _DisplayT[_ModelT]: ... def get_list_filter(self, request: HttpRequest) -> Sequence[_ListFilterT]: ... def get_list_select_related(self, request: HttpRequest) -> bool | Sequence[str]: ... def get_search_fields(self, request: HttpRequest) -> Sequence[str]: ... diff --git a/django-stubs/contrib/admin/views/main.pyi b/django-stubs/contrib/admin/views/main.pyi index 2f8012c41..3e0a7a2b2 100644 --- a/django-stubs/contrib/admin/views/main.pyi +++ b/django-stubs/contrib/admin/views/main.pyi @@ -26,8 +26,8 @@ class ChangeList: opts: Options[Model] lookup_opts: Options[Model] root_queryset: QuerySet[Model] - list_display: _DisplayT - list_display_links: _DisplayT + list_display: _DisplayT[Model] + list_display_links: _DisplayT[Model] list_filter: Sequence[_ListFilterT] date_hierarchy: Any search_fields: Sequence[str] @@ -52,8 +52,8 @@ class ChangeList: self, request: HttpRequest, model: type[Model], - list_display: _DisplayT, - list_display_links: _DisplayT, + list_display: _DisplayT[Model], + list_display_links: _DisplayT[Model], list_filter: Sequence[_ListFilterT], date_hierarchy: str | None, search_fields: Sequence[str], From f1a58500126a915f3fd908575dba258a18f27044 Mon Sep 17 00:00:00 2001 From: Christian Bundy Date: Mon, 23 Jan 2023 22:59:14 -0800 Subject: [PATCH 28/36] Fix Paginator --- django-stubs/contrib/admin/options.pyi | 2 +- django-stubs/contrib/sitemaps/__init__.pyi | 2 +- django-stubs/core/paginator.pyi | 6 +++--- django-stubs/views/generic/list.pyi | 6 +++--- 4 files changed, 8 insertions(+), 8 deletions(-) diff --git a/django-stubs/contrib/admin/options.pyi b/django-stubs/contrib/admin/options.pyi index 04fd71c89..e64c5419a 100644 --- a/django-stubs/contrib/admin/options.pyi +++ b/django-stubs/contrib/admin/options.pyi @@ -196,7 +196,7 @@ class ModelAdmin(BaseModelAdmin[_ModelT]): per_page: int, orphans: int = ..., allow_empty_first_page: bool = ..., - ) -> Paginator: ... + ) -> Paginator[_ModelT]: ... def log_addition(self, request: HttpRequest, object: _ModelT, message: Any) -> LogEntry: ... def log_change(self, request: HttpRequest, object: _ModelT, message: Any) -> LogEntry: ... def log_deletion(self, request: HttpRequest, object: _ModelT, object_repr: str) -> LogEntry: ... diff --git a/django-stubs/contrib/sitemaps/__init__.pyi b/django-stubs/contrib/sitemaps/__init__.pyi index 03c99772c..7a50c12a7 100644 --- a/django-stubs/contrib/sitemaps/__init__.pyi +++ b/django-stubs/contrib/sitemaps/__init__.pyi @@ -26,7 +26,7 @@ class Sitemap(Generic[_ItemT]): def items(self) -> Iterable[_ItemT]: ... def location(self, item: _ItemT) -> str: ... @property - def paginator(self) -> Paginator: ... + def paginator(self) -> Paginator[_ItemT]: ... def get_urls( self, page: int | str = ..., site: Site | RequestSite | None = ..., protocol: str | None = ... ) -> list[dict[str, Any]]: ... diff --git a/django-stubs/core/paginator.pyi b/django-stubs/core/paginator.pyi index 147a117e3..97ad41499 100644 --- a/django-stubs/core/paginator.pyi +++ b/django-stubs/core/paginator.pyi @@ -1,5 +1,5 @@ from collections.abc import Iterable, Iterator, Sequence, Sized -from typing import Generic, Protocol, TypeVar, overload +from typing import Any, Generic, Protocol, TypeVar, overload from django.db.models.base import Model from django.db.models.query import QuerySet @@ -49,12 +49,12 @@ QuerySetPaginator: TypeAlias = Paginator class Page(Sequence[_T]): object_list: _SupportsPagination[_T] number: int - paginator: Paginator + paginator: Paginator[_T] def __init__( self, object_list: _SupportsPagination[_T], number: int, - paginator: Paginator, + paginator: Paginator[_T], ) -> None: ... @overload def __getitem__(self, index: int) -> _T: ... diff --git a/django-stubs/views/generic/list.pyi b/django-stubs/views/generic/list.pyi index 89c273ee0..e0271ea82 100644 --- a/django-stubs/views/generic/list.pyi +++ b/django-stubs/views/generic/list.pyi @@ -15,14 +15,14 @@ class MultipleObjectMixin(Generic[_M], ContextMixin): paginate_by: int paginate_orphans: int context_object_name: str | None - paginator_class: type[Paginator] + paginator_class: type[Paginator[_M]] page_kwarg: str ordering: str | Sequence[str] | None def get_queryset(self) -> _SupportsPagination[_M]: ... def get_ordering(self) -> str | Sequence[str] | None: ... def paginate_queryset( self, queryset: _SupportsPagination[_M], page_size: int - ) -> tuple[Paginator, Page, _SupportsPagination[_M], bool]: ... + ) -> tuple[Paginator[_M], Page, _SupportsPagination[_M], bool]: ... def get_paginate_by(self, queryset: _SupportsPagination[_M]) -> int | None: ... def get_paginator( self, @@ -31,7 +31,7 @@ class MultipleObjectMixin(Generic[_M], ContextMixin): orphans: int = ..., allow_empty_first_page: bool = ..., **kwargs: Any - ) -> Paginator: ... + ) -> Paginator[_M]: ... def get_paginate_orphans(self) -> int: ... def get_allow_empty(self) -> bool: ... def get_context_object_name(self, object_list: _SupportsPagination[_M]) -> str | None: ... From 02d878a325b9a18175008abd4c9b69890cc8c9b8 Mon Sep 17 00:00:00 2001 From: Christian Bundy Date: Mon, 23 Jan 2023 23:00:58 -0800 Subject: [PATCH 29/36] Fix BooleanField --- django-stubs/contrib/flatpages/models.pyi | 4 ++-- django-stubs/contrib/postgres/fields/ranges.pyi | 10 +++++----- 2 files changed, 7 insertions(+), 7 deletions(-) diff --git a/django-stubs/contrib/flatpages/models.pyi b/django-stubs/contrib/flatpages/models.pyi index 4c8d42540..1d6ffcded 100644 --- a/django-stubs/contrib/flatpages/models.pyi +++ b/django-stubs/contrib/flatpages/models.pyi @@ -7,8 +7,8 @@ class FlatPage(models.Model): url: models.CharField[Any, Any] title: models.CharField[Any, Any] content: models.TextField - enable_comments: models.BooleanField + enable_comments: models.BooleanField[Any, Any] template_name: models.CharField[Any, Any] - registration_required: models.BooleanField + registration_required: models.BooleanField[Any, Any] sites: models.ManyToManyField[Site, Site] def get_absolute_url(self) -> str: ... diff --git a/django-stubs/contrib/postgres/fields/ranges.pyi b/django-stubs/contrib/postgres/fields/ranges.pyi index a394f7a7a..dea1d300e 100644 --- a/django-stubs/contrib/postgres/fields/ranges.pyi +++ b/django-stubs/contrib/postgres/fields/ranges.pyi @@ -88,24 +88,24 @@ class RangeEndsWith(models.Transform): class IsEmpty(models.Transform): lookup_name: str function: str - output_field: models.BooleanField + output_field: models.BooleanField[Any, Any] class LowerInclusive(models.Transform): lookup_name: str function: str - output_field: models.BooleanField + output_field: models.BooleanField[Any, Any] class LowerInfinite(models.Transform): lookup_name: str function: str - output_field: models.BooleanField + output_field: models.BooleanField[Any, Any] class UpperInclusive(models.Transform): lookup_name: str function: str - output_field: models.BooleanField + output_field: models.BooleanField[Any, Any] class UpperInfinite(models.Transform): lookup_name: str function: str - output_field: models.BooleanField + output_field: models.BooleanField[Any, Any] From f7cc2798bda8dff06a3578beeed060401704b4f1 Mon Sep 17 00:00:00 2001 From: Christian Bundy Date: Mon, 23 Jan 2023 23:11:30 -0800 Subject: [PATCH 30/36] Fix fields --- django-stubs/contrib/admin/filters.pyi | 2 +- django-stubs/contrib/admin/helpers.pyi | 2 +- django-stubs/contrib/admin/models.pyi | 8 ++++---- django-stubs/contrib/admin/options.pyi | 4 ++-- django-stubs/contrib/flatpages/models.pyi | 2 +- django-stubs/contrib/gis/db/models/fields.pyi | 4 ++-- django-stubs/contrib/gis/db/models/sql/conversion.pyi | 4 ++-- django-stubs/contrib/postgres/fields/citext.pyi | 4 ++-- django-stubs/core/serializers/base.pyi | 2 +- django-stubs/db/models/fields/related.pyi | 4 ++-- django-stubs/db/models/fields/related_descriptors.pyi | 6 +++--- django-stubs/db/models/fields/reverse_related.pyi | 8 ++++---- django-stubs/db/models/functions/datetime.pyi | 6 +++--- django-stubs/db/models/functions/window.pyi | 4 ++-- 14 files changed, 30 insertions(+), 30 deletions(-) diff --git a/django-stubs/contrib/admin/filters.pyi b/django-stubs/contrib/admin/filters.pyi index b94d58f97..27bccc967 100644 --- a/django-stubs/contrib/admin/filters.pyi +++ b/django-stubs/contrib/admin/filters.pyi @@ -69,7 +69,7 @@ class RelatedFieldListFilter(FieldListFilter): @property def include_empty_choice(self) -> bool: ... def field_choices( - self, field: RelatedField, request: HttpRequest, model_admin: ModelAdmin[Model] + self, field: RelatedField[Any, Any], request: HttpRequest, model_admin: ModelAdmin[Model] ) -> list[tuple[str, str]]: ... def choices(self, changelist: Any) -> Iterator[dict[str, Any]]: ... diff --git a/django-stubs/contrib/admin/helpers.pyi b/django-stubs/contrib/admin/helpers.pyi index 1fcb9faa5..198935ef6 100644 --- a/django-stubs/contrib/admin/helpers.pyi +++ b/django-stubs/contrib/admin/helpers.pyi @@ -168,7 +168,7 @@ class InlineAdminForm(AdminForm): view_on_site_url: str | None = ..., ) -> None: ... def __iter__(self) -> Iterator[InlineFieldset]: ... - def needs_explicit_pk_field(self) -> bool | AutoField: ... + def needs_explicit_pk_field(self) -> bool | AutoField[Any, Any]: ... def pk_field(self) -> AdminField: ... def fk_field(self) -> AdminField: ... def deletion_field(self) -> AdminField: ... diff --git a/django-stubs/contrib/admin/models.pyi b/django-stubs/contrib/admin/models.pyi index 9c271cde1..859875180 100644 --- a/django-stubs/contrib/admin/models.pyi +++ b/django-stubs/contrib/admin/models.pyi @@ -21,13 +21,13 @@ class LogEntryManager(models.Manager[LogEntry]): ) -> LogEntry: ... class LogEntry(models.Model): - action_time: models.DateTimeField + action_time: models.DateTimeField[Any, Any] user: models.ForeignKey[Any, Any] content_type: models.ForeignKey[Any, Any] - object_id: models.TextField + object_id: models.TextField[Any, Any] object_repr: models.CharField[Any, Any] - action_flag: models.PositiveSmallIntegerField - change_message: models.TextField + action_flag: models.PositiveSmallIntegerField[Any, Any] + change_message: models.TextField[Any, Any] objects: LogEntryManager def is_addition(self) -> bool: ... def is_change(self) -> bool: ... diff --git a/django-stubs/contrib/admin/options.pyi b/django-stubs/contrib/admin/options.pyi index e64c5419a..6f2e82639 100644 --- a/django-stubs/contrib/admin/options.pyi +++ b/django-stubs/contrib/admin/options.pyi @@ -106,13 +106,13 @@ class BaseModelAdmin(Generic[_ModelT]): self, db_field: Field[Any, Any], request: HttpRequest, **kwargs: Any ) -> TypedChoiceField: ... def get_field_queryset( - self, db: str | None, db_field: RelatedField, request: HttpRequest + self, db: str | None, db_field: RelatedField[Any, Any], request: HttpRequest ) -> QuerySet[Model] | None: ... def formfield_for_foreignkey( self, db_field: ForeignKey[Any, Any], request: HttpRequest, **kwargs: Any ) -> ModelChoiceField: ... def formfield_for_manytomany( - self, db_field: ManyToManyField, request: HttpRequest, **kwargs: Any + self, db_field: ManyToManyField[Any, Any], request: HttpRequest, **kwargs: Any ) -> ModelMultipleChoiceField | None: ... def get_autocomplete_fields(self, request: HttpRequest) -> Sequence[str]: ... def get_view_on_site_url(self, obj: _ModelT | None = ...) -> str | None: ... diff --git a/django-stubs/contrib/flatpages/models.pyi b/django-stubs/contrib/flatpages/models.pyi index 1d6ffcded..1a26fab42 100644 --- a/django-stubs/contrib/flatpages/models.pyi +++ b/django-stubs/contrib/flatpages/models.pyi @@ -6,7 +6,7 @@ from django.db import models class FlatPage(models.Model): url: models.CharField[Any, Any] title: models.CharField[Any, Any] - content: models.TextField + content: models.TextField[Any, Any] enable_comments: models.BooleanField[Any, Any] template_name: models.CharField[Any, Any] registration_required: models.BooleanField[Any, Any] diff --git a/django-stubs/contrib/gis/db/models/fields.pyi b/django-stubs/contrib/gis/db/models/fields.pyi index f1e8b68dd..caa059f90 100644 --- a/django-stubs/contrib/gis/db/models/fields.pyi +++ b/django-stubs/contrib/gis/db/models/fields.pyi @@ -75,7 +75,7 @@ class BaseSpatialField(Field[_ST, _GT]): def get_raster_prep_value(self, value: Any, is_candidate: Any) -> Any: ... def get_prep_value(self, value: Any) -> Any: ... -class GeometryField(BaseSpatialField): +class GeometryField(BaseSpatialField[Any, Any]): dim: int def __init__( self, @@ -144,7 +144,7 @@ class ExtentField(Field[Any, Any]): def get_internal_type(self) -> Any: ... def select_format(self, compiler: Any, sql: Any, params: Any) -> Any: ... -class RasterField(BaseSpatialField): +class RasterField(BaseSpatialField[Any, Any]): def db_type(self, connection: Any) -> Any: ... def from_db_value(self, value: Any, expression: Any, connection: Any) -> Any: ... def get_transform(self, name: Any) -> Any: ... diff --git a/django-stubs/contrib/gis/db/models/sql/conversion.pyi b/django-stubs/contrib/gis/db/models/sql/conversion.pyi index 50c08f5ee..4b03fd0ec 100644 --- a/django-stubs/contrib/gis/db/models/sql/conversion.pyi +++ b/django-stubs/contrib/gis/db/models/sql/conversion.pyi @@ -2,7 +2,7 @@ from typing import Any from django.db import models as models -class AreaField(models.FloatField): +class AreaField(models.FloatField[Any, Any]): geo_field: Any def __init__(self, geo_field: Any) -> None: ... def get_prep_value(self, value: Any) -> Any: ... @@ -10,7 +10,7 @@ class AreaField(models.FloatField): def from_db_value(self, value: Any, expression: Any, connection: Any) -> Any: ... def get_internal_type(self) -> Any: ... -class DistanceField(models.FloatField): +class DistanceField(models.FloatField[Any, Any]): geo_field: Any def __init__(self, geo_field: Any) -> None: ... def get_prep_value(self, value: Any) -> Any: ... diff --git a/django-stubs/contrib/postgres/fields/citext.pyi b/django-stubs/contrib/postgres/fields/citext.pyi index c54b1087d..0d94d9a63 100644 --- a/django-stubs/contrib/postgres/fields/citext.pyi +++ b/django-stubs/contrib/postgres/fields/citext.pyi @@ -4,5 +4,5 @@ from django.db.models.fields import CharField, EmailField, TextField class CIText: ... class CICharField(CIText, CharField[Any, Any]): ... -class CIEmailField(CIText, EmailField): ... -class CITextField(CIText, TextField): ... +class CIEmailField(CIText, EmailField[Any, Any]): ... +class CITextField(CIText, TextField[Any, Any]): ... diff --git a/django-stubs/core/serializers/base.pyi b/django-stubs/core/serializers/base.pyi index 8d20e2112..23486b0ba 100644 --- a/django-stubs/core/serializers/base.pyi +++ b/django-stubs/core/serializers/base.pyi @@ -82,7 +82,7 @@ class DeserializedObject: def build_instance(Model: type[Model], data: dict[str, Any], db: str) -> Model: ... def deserialize_m2m_values( - field: ManyToManyField, field_value: Iterable[Any], using: str | None, handle_forward_references: bool + field: ManyToManyField[Any, Any], field_value: Iterable[Any], using: str | None, handle_forward_references: bool ) -> Sequence[Any] | object: ... def deserialize_fk_value( field: ForeignKey[Any, Any], field_value: Any, using: str | None, handle_forward_references: bool diff --git a/django-stubs/db/models/fields/related.pyi b/django-stubs/db/models/fields/related.pyi index 9eed3f011..61fef9342 100644 --- a/django-stubs/db/models/fields/related.pyi +++ b/django-stubs/db/models/fields/related.pyi @@ -263,7 +263,7 @@ class ManyToManyField(RelatedField[_ST, _GT]): def __get__(self: Self, instance: Any, owner: Any) -> Self: ... def get_path_info(self, filtered_relation: FilteredRelation | None = ...) -> list[PathInfo]: ... def get_reverse_path_info(self, filtered_relation: FilteredRelation | None = ...) -> list[PathInfo]: ... - def contribute_to_related_class(self, cls: type[Model], related: RelatedField) -> None: ... + def contribute_to_related_class(self, cls: type[Model], related: RelatedField[Any, Any]) -> None: ... def m2m_db_table(self) -> str: ... def m2m_column_name(self) -> str: ... def m2m_reverse_name(self) -> str: ... @@ -271,4 +271,4 @@ class ManyToManyField(RelatedField[_ST, _GT]): def m2m_target_field_name(self) -> str: ... def m2m_reverse_target_field_name(self) -> str: ... -def create_many_to_many_intermediary_model(field: ManyToManyField, klass: type[Model]) -> type[Model]: ... +def create_many_to_many_intermediary_model(field: ManyToManyField[Any, Any], klass: type[Model]) -> type[Model]: ... diff --git a/django-stubs/db/models/fields/related_descriptors.pyi b/django-stubs/db/models/fields/related_descriptors.pyi index 424eb4dae..752ead26c 100644 --- a/django-stubs/db/models/fields/related_descriptors.pyi +++ b/django-stubs/db/models/fields/related_descriptors.pyi @@ -14,7 +14,7 @@ from django.db.models.query_utils import DeferredAttribute _T = TypeVar("_T") class ForeignKeyDeferredAttribute(DeferredAttribute): - field: RelatedField + field: RelatedField[Any, Any] class ForwardManyToOneDescriptor: field: ForeignKey[Any, Any] @@ -34,7 +34,7 @@ class ForwardManyToOneDescriptor: def __reduce__(self) -> tuple[Callable[..., Any], tuple[type[Model], str]]: ... class ForwardOneToOneDescriptor(ForwardManyToOneDescriptor): - field: OneToOneField + field: OneToOneField[Any, Any] def get_object(self, instance: Model) -> Model: ... class ReverseOneToOneDescriptor: @@ -63,7 +63,7 @@ class ReverseManyToOneDescriptor: def create_reverse_many_to_one_manager(superclass: type, rel: Any) -> type[RelatedManager]: ... class ManyToManyDescriptor(ReverseManyToOneDescriptor): - field: ManyToManyField # type: ignore[assignment] + field: ManyToManyField[Any, Any] # type: ignore[assignment] rel: ManyToManyRel # type: ignore[assignment] reverse: bool def __init__(self, rel: ManyToManyRel, reverse: bool = ...) -> None: ... diff --git a/django-stubs/db/models/fields/reverse_related.pyi b/django-stubs/db/models/fields/reverse_related.pyi index 8d1588960..349da5d61 100644 --- a/django-stubs/db/models/fields/reverse_related.pyi +++ b/django-stubs/db/models/fields/reverse_related.pyi @@ -50,7 +50,7 @@ class ForeignObjectRel(FieldCacheMixin): @property def remote_field(self) -> ForeignObject: ... @property - def target_field(self) -> AutoField: ... + def target_field(self) -> AutoField[Any, Any]: ... @property def related_model(self) -> type[Model]: ... @property @@ -99,10 +99,10 @@ class ManyToOneRel(ForeignObjectRel): def get_related_field(self) -> Field[Any, Any]: ... class OneToOneRel(ManyToOneRel): - field: OneToOneField + field: OneToOneField[Any, Any] def __init__( self, - field: OneToOneField, + field: OneToOneField[Any, Any], to: type[Model] | str, field_name: str | None, related_name: str | None = ..., @@ -119,7 +119,7 @@ class ManyToManyRel(ForeignObjectRel): db_constraint: bool def __init__( self, - field: ManyToManyField, + field: ManyToManyField[Any, Any], to: type[Model] | str, related_name: str | None = ..., related_query_name: str | None = ..., diff --git a/django-stubs/db/models/functions/datetime.pyi b/django-stubs/db/models/functions/datetime.pyi index a2713ed9b..48b838691 100644 --- a/django-stubs/db/models/functions/datetime.pyi +++ b/django-stubs/db/models/functions/datetime.pyi @@ -27,7 +27,7 @@ class ExtractMinute(Extract): ... class ExtractSecond(Extract): ... class Now(Func): - output_field: models.DateTimeField + output_field: models.DateTimeField[Any, Any] class TruncBase(TimezoneMixin, Transform): kind: str @@ -41,10 +41,10 @@ class TruncWeek(TruncBase): ... class TruncDay(TruncBase): ... class TruncDate(TruncBase): - output_field: models.DateField + output_field: models.DateField[Any, Any] class TruncTime(TruncBase): - output_field: models.TimeField + output_field: models.TimeField[Any, Any] class TruncHour(TruncBase): ... class TruncMinute(TruncBase): ... diff --git a/django-stubs/db/models/functions/window.pyi b/django-stubs/db/models/functions/window.pyi index 33e93d52e..78cb40678 100644 --- a/django-stubs/db/models/functions/window.pyi +++ b/django-stubs/db/models/functions/window.pyi @@ -4,7 +4,7 @@ from django.db import models from django.db.models.expressions import Func class CumeDist(Func): - output_field: models.FloatField + output_field: models.FloatField[Any, Any] class DenseRank(Func): output_field: models.IntegerField[Any, Any] @@ -26,7 +26,7 @@ class Ntile(Func): output_field: models.IntegerField[Any, Any] class PercentRank(Func): - output_field: models.FloatField + output_field: models.FloatField[Any, Any] class Rank(Func): output_field: models.IntegerField[Any, Any] From bbee01e51cabdae90037461abd504af90f4f47de Mon Sep 17 00:00:00 2001 From: Christian Bundy Date: Mon, 23 Jan 2023 23:13:26 -0800 Subject: [PATCH 31/36] Fix BaseModelAdmin --- django-stubs/contrib/admin/checks.pyi | 5 +++-- django-stubs/contrib/admin/utils.pyi | 6 +++--- 2 files changed, 6 insertions(+), 5 deletions(-) diff --git a/django-stubs/contrib/admin/checks.pyi b/django-stubs/contrib/admin/checks.pyi index ecef0ea7f..15d0b5054 100644 --- a/django-stubs/contrib/admin/checks.pyi +++ b/django-stubs/contrib/admin/checks.pyi @@ -4,15 +4,16 @@ from typing import Any from django.apps.config import AppConfig from django.contrib.admin.options import BaseModelAdmin from django.core.checks.messages import CheckMessage, Error +from django.db.models import Model def check_admin_app(app_configs: Sequence[AppConfig] | None, **kwargs: Any) -> list[CheckMessage]: ... def check_dependencies(**kwargs: Any) -> list[CheckMessage]: ... class BaseModelAdminChecks: - def check(self, admin_obj: BaseModelAdmin, **kwargs: Any) -> list[CheckMessage]: ... + def check(self, admin_obj: BaseModelAdmin[Model], **kwargs: Any) -> list[CheckMessage]: ... class ModelAdminChecks(BaseModelAdminChecks): - def check(self, admin_obj: BaseModelAdmin, **kwargs: Any) -> list[CheckMessage]: ... + def check(self, admin_obj: BaseModelAdmin[Model], **kwargs: Any) -> list[CheckMessage]: ... class InlineModelAdminChecks(BaseModelAdminChecks): def check(self, inline_obj: BaseModelAdmin, **kwargs: Any) -> list[CheckMessage]: ... # type: ignore diff --git a/django-stubs/contrib/admin/utils.pyi b/django-stubs/contrib/admin/utils.pyi index bf06d9fd6..dae827de4 100644 --- a/django-stubs/contrib/admin/utils.pyi +++ b/django-stubs/contrib/admin/utils.pyi @@ -53,13 +53,13 @@ class _ModelFormatDict(TypedDict): def model_format_dict(obj: Model | type[Model] | QuerySet[Model] | Options[Model]) -> _ModelFormatDict: ... def model_ngettext(obj: Options[Model] | QuerySet[Model], n: int | None = ...) -> str: ... def lookup_field( - name: Callable[..., Any] | str, obj: Model, model_admin: BaseModelAdmin | None = ... + name: Callable[..., Any] | str, obj: Model, model_admin: BaseModelAdmin[Model] | None = ... ) -> tuple[Field[Any, Any] | None, str | None, Any]: ... @overload def label_for_field( # type: ignore name: Callable[..., Any] | str, model: type[Model], - model_admin: BaseModelAdmin | None = ..., + model_admin: BaseModelAdmin[Model] | None = ..., return_attr: Literal[True] = ..., form: BaseForm | None = ..., ) -> tuple[str, Callable[..., Any] | str | None]: ... @@ -67,7 +67,7 @@ def label_for_field( # type: ignore def label_for_field( name: Callable[..., Any] | str, model: type[Model], - model_admin: BaseModelAdmin | None = ..., + model_admin: BaseModelAdmin[Model] | None = ..., return_attr: Literal[False] = ..., form: BaseForm | None = ..., ) -> str: ... From 9f682c785b4faa90e6df14d98070a2dec436a0fa Mon Sep 17 00:00:00 2001 From: Christian Bundy Date: Mon, 23 Jan 2023 23:14:33 -0800 Subject: [PATCH 32/36] Fix Sitemap --- django-stubs/contrib/flatpages/sitemaps.pyi | 4 +++- django-stubs/contrib/gis/sitemaps/kml.pyi | 2 +- django-stubs/contrib/sitemaps/views.pyi | 4 ++-- 3 files changed, 6 insertions(+), 4 deletions(-) diff --git a/django-stubs/contrib/flatpages/sitemaps.pyi b/django-stubs/contrib/flatpages/sitemaps.pyi index e67408371..ecfb31f53 100644 --- a/django-stubs/contrib/flatpages/sitemaps.pyi +++ b/django-stubs/contrib/flatpages/sitemaps.pyi @@ -1,3 +1,5 @@ +from typing import Any + from django.contrib.sitemaps import Sitemap -class FlatPageSitemap(Sitemap): ... +class FlatPageSitemap(Sitemap[Any]): ... diff --git a/django-stubs/contrib/gis/sitemaps/kml.pyi b/django-stubs/contrib/gis/sitemaps/kml.pyi index 3b65b9262..ef33e1fc2 100644 --- a/django-stubs/contrib/gis/sitemaps/kml.pyi +++ b/django-stubs/contrib/gis/sitemaps/kml.pyi @@ -2,7 +2,7 @@ from typing import Any from django.contrib.sitemaps import Sitemap as Sitemap -class KMLSitemap(Sitemap): +class KMLSitemap(Sitemap[Any]): geo_format: str locations: Any def __init__(self, locations: Any | None = ...) -> None: ... diff --git a/django-stubs/contrib/sitemaps/views.pyi b/django-stubs/contrib/sitemaps/views.pyi index e36b9dc55..fa287186d 100644 --- a/django-stubs/contrib/sitemaps/views.pyi +++ b/django-stubs/contrib/sitemaps/views.pyi @@ -10,14 +10,14 @@ _C = TypeVar("_C", bound=Callable[..., Any]) def x_robots_tag(func: _C) -> _C: ... def index( request: HttpRequest, - sitemaps: dict[str, type[Sitemap] | Sitemap], + sitemaps: dict[str, type[Sitemap[Any]] | Sitemap[Any]], template_name: str = ..., content_type: str = ..., sitemap_url_name: str = ..., ) -> TemplateResponse: ... def sitemap( request: HttpRequest, - sitemaps: dict[str, type[Sitemap] | Sitemap], + sitemaps: dict[str, type[Sitemap[Any]] | Sitemap[Any]], section: str | None = ..., template_name: str = ..., content_type: str = ..., From 3e1e1ab807d074a6c95b42b4de17abb2636ee991 Mon Sep 17 00:00:00 2001 From: Christian Bundy Date: Mon, 23 Jan 2023 23:18:43 -0800 Subject: [PATCH 33/36] Fix MultiValueDict --- django-stubs/core/handlers/asgi.pyi | 2 +- django-stubs/core/management/commands/makemessages.pyi | 4 ++-- django-stubs/db/models/sql/constants.pyi | 3 ++- django-stubs/http/multipartparser.pyi | 2 +- django-stubs/test/client.pyi | 6 +++--- django-stubs/urls/resolvers.pyi | 4 ++-- 6 files changed, 11 insertions(+), 10 deletions(-) diff --git a/django-stubs/core/handlers/asgi.pyi b/django-stubs/core/handlers/asgi.pyi index 88621620e..125e37d91 100644 --- a/django-stubs/core/handlers/asgi.pyi +++ b/django-stubs/core/handlers/asgi.pyi @@ -25,7 +25,7 @@ class ASGIRequest(HttpRequest): @property def GET(self) -> _ImmutableQueryDict: ... # type: ignore POST: _ImmutableQueryDict - FILES: MultiValueDict + FILES: MultiValueDict[Any, Any] @property def COOKIES(self) -> dict[str, str]: ... # type: ignore diff --git a/django-stubs/core/management/commands/makemessages.pyi b/django-stubs/core/management/commands/makemessages.pyi index 78def0673..9e4d08d64 100644 --- a/django-stubs/core/management/commands/makemessages.pyi +++ b/django-stubs/core/management/commands/makemessages.pyi @@ -1,9 +1,9 @@ from re import Pattern -from typing import Any +from typing import Any, AnyStr from django.core.management.base import BaseCommand -plural_forms_re: Pattern +plural_forms_re: Pattern[AnyStr] STATUS_OK: int NO_LOCALE_DIR: Any diff --git a/django-stubs/db/models/sql/constants.pyi b/django-stubs/db/models/sql/constants.pyi index a6b068a3c..03fafcc03 100644 --- a/django-stubs/db/models/sql/constants.pyi +++ b/django-stubs/db/models/sql/constants.pyi @@ -1,4 +1,5 @@ from re import Pattern +from typing import AnyStr from typing_extensions import Final, Literal @@ -9,7 +10,7 @@ SINGLE: Literal["single"] CURSOR: Literal["cursor"] NO_RESULTS: Literal["no results"] -ORDER_PATTERN: Pattern +ORDER_PATTERN: Pattern[AnyStr] ORDER_DIR: dict[str, tuple[str, str]] INNER: Literal["INNER JOIN"] diff --git a/django-stubs/http/multipartparser.pyi b/django-stubs/http/multipartparser.pyi index 830e784f6..d5cdfbd31 100644 --- a/django-stubs/http/multipartparser.pyi +++ b/django-stubs/http/multipartparser.pyi @@ -20,7 +20,7 @@ class MultiPartParser: upload_handlers: list[Any] | ImmutableList[Any], encoding: str | None = ..., ) -> None: ... - def parse(self) -> tuple[QueryDict, MultiValueDict]: ... + def parse(self) -> tuple[QueryDict, MultiValueDict[Any, Any]]: ... def handle_file_complete(self, old_field_name: str, counters: list[int]) -> None: ... def sanitize_file_name(self, file_name: str) -> str | None: ... diff --git a/django-stubs/test/client.pyi b/django-stubs/test/client.pyi index 3e553aa2b..7f176427d 100644 --- a/django-stubs/test/client.pyi +++ b/django-stubs/test/client.pyi @@ -3,7 +3,7 @@ from io import BytesIO from json import JSONEncoder from re import Pattern from types import TracebackType -from typing import Any, Generic, NoReturn, TypeVar +from typing import Any, AnyStr, Generic, NoReturn, TypeVar from django.contrib.auth.base_user import AbstractBaseUser from django.contrib.sessions.backends.base import SessionBase @@ -20,8 +20,8 @@ from typing_extensions import TypeAlias BOUNDARY: str MULTIPART_CONTENT: str -CONTENT_TYPE_RE: Pattern -JSON_CONTENT_TYPE_RE: Pattern +CONTENT_TYPE_RE: Pattern[AnyStr] +JSON_CONTENT_TYPE_RE: Pattern[AnyStr] class RedirectCycleError(Exception): last_response: HttpResponseBase diff --git a/django-stubs/urls/resolvers.pyi b/django-stubs/urls/resolvers.pyi index 3d554a8a7..ed1ffd2d4 100644 --- a/django-stubs/urls/resolvers.pyi +++ b/django-stubs/urls/resolvers.pyi @@ -106,7 +106,7 @@ class URLResolver: namespace: str | None app_name: str | None _local: Any - _reverse_dict: MultiValueDict + _reverse_dict: MultiValueDict[Any, Any] def __init__( self, pattern: _Pattern, @@ -116,7 +116,7 @@ class URLResolver: namespace: str | None = ..., ) -> None: ... @property - def reverse_dict(self) -> MultiValueDict: ... + def reverse_dict(self) -> MultiValueDict[Any, Any]: ... @property def namespace_dict(self) -> dict[str, tuple[str, URLResolver]]: ... @property From 838c66d1fbf781894a2bea56e279978a977c85f2 Mon Sep 17 00:00:00 2001 From: Christian Bundy Date: Tue, 24 Jan 2023 00:37:14 -0800 Subject: [PATCH 34/36] Fix the rest of the errors --- django-stubs/contrib/admin/decorators.pyi | 2 +- django-stubs/contrib/admin/options.pyi | 21 ++++++++++++------- django-stubs/contrib/admin/utils.pyi | 2 +- .../contrib/admin/views/autocomplete.pyi | 2 +- django-stubs/contrib/admin/views/main.pyi | 3 ++- django-stubs/contrib/admin/widgets.pyi | 13 ++++-------- django-stubs/contrib/auth/views.pyi | 7 ++++--- django-stubs/contrib/contenttypes/admin.pyi | 2 +- django-stubs/contrib/contenttypes/fields.pyi | 2 +- django-stubs/contrib/gis/feeds.pyi | 3 ++- django-stubs/core/cache/__init__.pyi | 2 +- django-stubs/core/checks/registry.pyi | 6 +++--- django-stubs/core/files/uploadedfile.pyi | 6 +++--- django-stubs/core/files/uploadhandler.pyi | 2 +- .../core/management/commands/makemessages.pyi | 2 +- django-stubs/core/management/utils.pyi | 4 ++-- django-stubs/core/paginator.pyi | 2 +- django-stubs/db/models/fields/__init__.pyi | 2 +- django-stubs/db/models/fields/files.pyi | 8 +++---- django-stubs/db/models/fields/json.pyi | 12 +++++------ .../db/models/fields/related_descriptors.pyi | 6 +++--- .../db/models/fields/related_lookups.pyi | 10 ++++----- .../db/models/fields/reverse_related.pyi | 6 +++--- django-stubs/db/models/lookups.pyi | 4 ++-- django-stubs/db/models/manager.pyi | 8 +++---- django-stubs/db/models/query.pyi | 6 +++--- django-stubs/db/models/sql/constants.pyi | 4 ++-- django-stubs/db/models/sql/query.pyi | 2 +- django-stubs/forms/forms.pyi | 2 +- django-stubs/forms/formsets.pyi | 2 +- django-stubs/forms/models.pyi | 4 ++-- django-stubs/forms/utils.pyi | 2 +- django-stubs/http/request.pyi | 2 +- django-stubs/template/loader_tags.pyi | 2 +- django-stubs/template/response.pyi | 2 +- django-stubs/test/client.pyi | 4 ++-- django-stubs/test/runner.pyi | 8 +++++-- django-stubs/test/testcases.pyi | 6 +++--- django-stubs/test/utils.pyi | 6 +++--- django-stubs/utils/decorators.pyi | 2 +- django-stubs/utils/termcolors.pyi | 2 +- django-stubs/utils/translation/__init__.pyi | 2 +- django-stubs/views/generic/dates.pyi | 20 +++++++++--------- django-stubs/views/generic/edit.pyi | 2 +- django-stubs/views/generic/list.pyi | 2 +- 45 files changed, 114 insertions(+), 105 deletions(-) diff --git a/django-stubs/contrib/admin/decorators.pyi b/django-stubs/contrib/admin/decorators.pyi index e57837cb2..7df6d8266 100644 --- a/django-stubs/contrib/admin/decorators.pyi +++ b/django-stubs/contrib/admin/decorators.pyi @@ -16,7 +16,7 @@ _Request = TypeVar("_Request", bound=HttpRequest) _QuerySet = TypeVar("_QuerySet", bound=QuerySet[Model]) # This is deliberately different from _DisplayT defined in contrib.admin.options _DisplayCallable: TypeAlias = Union[Callable[[_ModelAdmin, _Model], Any], Callable[[_Model], Any]] # noqa: Y037 -_DisplayCallableT = TypeVar("_DisplayCallableT", bound=_DisplayCallable) +_DisplayCallableT = TypeVar("_DisplayCallableT", bound=_DisplayCallable[ModelAdmin[Model], Model]) _ActionReturn = TypeVar("_ActionReturn", bound=HttpResponseBase | None) @overload diff --git a/django-stubs/contrib/admin/options.pyi b/django-stubs/contrib/admin/options.pyi index 6f2e82639..592f8c844 100644 --- a/django-stubs/contrib/admin/options.pyi +++ b/django-stubs/contrib/admin/options.pyi @@ -15,6 +15,7 @@ from django.db.models.fields import Field from django.db.models.fields.related import ForeignKey, ManyToManyField, RelatedField from django.db.models.options import Options from django.db.models.query import QuerySet +from django.forms import BaseForm from django.forms.fields import Field as FormField from django.forms.fields import TypedChoiceField from django.forms.formsets import BaseFormSet @@ -120,7 +121,7 @@ class BaseModelAdmin(Generic[_ModelT]): def get_exclude(self, request: HttpRequest, obj: _ModelT | None = ...) -> Sequence[str] | None: ... def get_fields(self, request: HttpRequest, obj: _ModelT | None = ...) -> _FieldGroups: ... def get_fieldsets(self, request: HttpRequest, obj: _ModelT | None = ...) -> _FieldsetSpec: ... - def get_inlines(self, request: HttpRequest, obj: _ModelT | None) -> list[type[InlineModelAdmin]]: ... + def get_inlines(self, request: HttpRequest, obj: _ModelT | None) -> list[type[InlineModelAdmin[Model, Model]]]: ... def get_ordering(self, request: HttpRequest) -> Sequence[str]: ... def get_readonly_fields(self, request: HttpRequest, obj: _ModelT | None = ...) -> Sequence[str]: ... def get_prepopulated_fields(self, request: HttpRequest, obj: _ModelT | None = ...) -> dict[str, Sequence[str]]: ... @@ -154,7 +155,7 @@ class ModelAdmin(BaseModelAdmin[_ModelT]): save_on_top: bool paginator: type preserve_filters: bool - inlines: Sequence[type[InlineModelAdmin]] + inlines: Sequence[type[InlineModelAdmin[Model, Model]]] add_form_template: _TemplateForResponseT | None change_form_template: _TemplateForResponseT | None change_list_template: _TemplateForResponseT | None @@ -171,7 +172,9 @@ class ModelAdmin(BaseModelAdmin[_ModelT]): opts: Options[_ModelT] admin_site: AdminSite def __init__(self, model: type[_ModelT], admin_site: AdminSite) -> None: ... - def get_inline_instances(self, request: HttpRequest, obj: _ModelT | None = ...) -> list[InlineModelAdmin]: ... + def get_inline_instances( + self, request: HttpRequest, obj: _ModelT | None = ... + ) -> list[InlineModelAdmin[Model, Model]]: ... def get_urls(self) -> list[URLPattern]: ... @property def urls(self) -> list[URLPattern]: ... @@ -187,7 +190,7 @@ class ModelAdmin(BaseModelAdmin[_ModelT]): def get_changelist_form(self, request: HttpRequest, **kwargs: Any) -> type[ModelForm[_ModelT]]: ... def get_changelist_formset( self, request: HttpRequest, **kwargs: Any - ) -> type[BaseModelFormSet[_ModelT, ModelForm[_ModelT]]]: ... + ) -> type[BaseModelFormSet[_ModelT, ModelForm[Model]]]: ... def get_formsets_with_inlines(self, request: HttpRequest, obj: _ModelT | None = ...) -> Iterator[Any]: ... def get_paginator( self, @@ -218,7 +221,11 @@ class ModelAdmin(BaseModelAdmin[_ModelT]): def _get_edited_object_pks(self, request: HttpRequest, prefix: str) -> list[str]: ... def _get_list_editable_queryset(self, request: HttpRequest, prefix: str) -> QuerySet[_ModelT]: ... def construct_change_message( - self, request: HttpRequest, form: AdminPasswordChangeForm, formsets: Iterable[BaseFormSet], add: bool = ... + self, + request: HttpRequest, + form: AdminPasswordChangeForm, + formsets: Iterable[BaseFormSet[BaseForm]], + add: bool = ..., ) -> list[dict[str, dict[str, list[str]]]]: ... def message_user( self, @@ -285,7 +292,7 @@ _ParentModelT = TypeVar("_ParentModelT", bound=Model) class InlineModelAdmin(Generic[_ChildModelT, _ParentModelT], BaseModelAdmin[_ChildModelT]): model: type[_ChildModelT] fk_name: str | None - formset: type[BaseInlineFormSet[_ChildModelT, _ParentModelT, forms.ModelForm[_ChildModelT]]] + formset: type[BaseInlineFormSet[_ChildModelT, _ParentModelT, forms.ModelForm[_ChildModelT]]] # type: ignore[type-var] extra: int min_num: int | None max_num: int | None @@ -307,7 +314,7 @@ class InlineModelAdmin(Generic[_ChildModelT, _ParentModelT], BaseModelAdmin[_Chi def get_max_num(self, request: HttpRequest, obj: _ParentModelT | None = ..., **kwargs: Any) -> int | None: ... def get_formset( self, request: HttpRequest, obj: _ParentModelT | None = ..., **kwargs: Any - ) -> type[BaseInlineFormSet[_ChildModelT, _ParentModelT, forms.ModelForm[_ChildModelT]]]: ... + ) -> type[BaseInlineFormSet[_ChildModelT, _ParentModelT, forms.ModelForm[_ChildModelT]]]: ... # type: ignore[type-var] def get_queryset(self, request: HttpRequest) -> QuerySet[_ChildModelT]: ... def has_add_permission(self, request: HttpRequest, obj: _ParentModelT | None) -> bool: ... # type: ignore def has_change_permission(self, request: HttpRequest, obj: _ParentModelT | None = ...) -> bool: ... # type: ignore diff --git a/django-stubs/contrib/admin/utils.pyi b/django-stubs/contrib/admin/utils.pyi index dae827de4..82548c06d 100644 --- a/django-stubs/contrib/admin/utils.pyi +++ b/django-stubs/contrib/admin/utils.pyi @@ -81,5 +81,5 @@ def get_model_from_relation(field: Field[Any, Any] | reverse_related.ForeignObje def reverse_field_path(model: type[Model], path: str) -> tuple[type[Model], str]: ... def get_fields_from_path(model: type[Model], path: str) -> list[Field[Any, Any]]: ... def construct_change_message( - form: AdminPasswordChangeForm, formsets: Iterable[BaseFormSet], add: bool + form: AdminPasswordChangeForm, formsets: Iterable[BaseFormSet[BaseForm]], add: bool ) -> list[dict[str, dict[str, list[str]]]]: ... diff --git a/django-stubs/contrib/admin/views/autocomplete.pyi b/django-stubs/contrib/admin/views/autocomplete.pyi index 8ac451009..18e7debd1 100644 --- a/django-stubs/contrib/admin/views/autocomplete.pyi +++ b/django-stubs/contrib/admin/views/autocomplete.pyi @@ -5,7 +5,7 @@ from django.db.models import Model from django.http.request import HttpRequest from django.views.generic.list import BaseListView -class AutocompleteJsonView(BaseListView): +class AutocompleteJsonView(BaseListView[Model]): model_admin: ModelAdmin[Model] term: Any def has_perm(self, request: HttpRequest, obj: Model | None = ...) -> bool: ... diff --git a/django-stubs/contrib/admin/views/main.pyi b/django-stubs/contrib/admin/views/main.pyi index 3e0a7a2b2..a9ad797f0 100644 --- a/django-stubs/contrib/admin/views/main.pyi +++ b/django-stubs/contrib/admin/views/main.pyi @@ -9,6 +9,7 @@ from django.db.models.base import Model from django.db.models.expressions import Expression from django.db.models.options import Options from django.db.models.query import QuerySet +from django.forms import BaseForm from django.forms.formsets import BaseFormSet from django.http.request import HttpRequest from typing_extensions import Literal @@ -47,7 +48,7 @@ class ChangeList: queryset: Any title: str pk_attname: str - formset: BaseFormSet | None + formset: BaseFormSet[BaseForm] | None def __init__( self, request: HttpRequest, diff --git a/django-stubs/contrib/admin/widgets.pyi b/django-stubs/contrib/admin/widgets.pyi index b462f32c6..9b8349714 100644 --- a/django-stubs/contrib/admin/widgets.pyi +++ b/django-stubs/contrib/admin/widgets.pyi @@ -7,6 +7,7 @@ from django.core.files.base import File from django.db.models.fields import _FieldChoices from django.db.models.fields.reverse_related import ForeignObjectRel, ManyToManyRel, ManyToOneRel from django.forms.models import ModelChoiceIterator +from django.forms.utils import _FilesT from django.forms.widgets import _OptAttrs from django.utils.functional import _StrOrPromise @@ -55,9 +56,7 @@ class ManyToManyRawIdWidget(ForeignKeyRawIdWidget): def url_parameters(self) -> dict[str, str]: ... def label_and_url_for_value(self, value: Any) -> tuple[str, str]: ... def format_value(self, value: Any) -> str | None: ... - def value_from_datadict( - self, data: Mapping[str, Any], files: Mapping[str, Iterable[File[AnyStr]]], name: str - ) -> Any: ... + def value_from_datadict(self, data: Mapping[str, Any], files: _FilesT[AnyStr], name: str) -> Any: ... class RelatedFieldWidgetWrapper(forms.Widget): template_name: str @@ -83,12 +82,8 @@ class RelatedFieldWidgetWrapper(forms.Widget): def is_hidden(self) -> bool: ... def get_related_url(self, info: tuple[str, str], action: str, *args: Any) -> str: ... def get_context(self, name: str, value: Any, attrs: _OptAttrs | None) -> dict[str, Any]: ... - def value_from_datadict( - self, data: Mapping[str, Any], files: Mapping[str, Iterable[File[AnyStr]]], name: str - ) -> Any: ... - def value_omitted_from_data( - self, data: Mapping[str, Any], files: Mapping[str, Iterable[File[AnyStr]]], name: str - ) -> bool: ... + def value_from_datadict(self, data: Mapping[str, Any], files: _FilesT[AnyStr], name: str) -> Any: ... + def value_omitted_from_data(self, data: Mapping[str, Any], files: _FilesT[AnyStr], name: str) -> bool: ... def id_for_label(self, id_: str) -> str: ... class AdminTextareaWidget(forms.Textarea): diff --git a/django-stubs/contrib/auth/views.pyi b/django-stubs/contrib/auth/views.pyi index b669fcf13..1d232850f 100644 --- a/django-stubs/contrib/auth/views.pyi +++ b/django-stubs/contrib/auth/views.pyi @@ -2,6 +2,7 @@ from typing import Any from django.contrib.auth.base_user import AbstractBaseUser from django.contrib.auth.forms import AuthenticationForm +from django.forms import BaseForm from django.http.request import HttpRequest from django.http.response import HttpResponse, HttpResponseRedirect from django.views.generic.base import TemplateView @@ -37,7 +38,7 @@ class PasswordContextMixin: extra_context: Any def get_context_data(self, **kwargs: Any) -> dict[str, Any]: ... -class PasswordResetView(PasswordContextMixin, FormView): +class PasswordResetView(PasswordContextMixin, FormView[BaseForm]): email_template_name: str extra_email_context: Any from_email: Any @@ -52,7 +53,7 @@ INTERNAL_RESET_SESSION_TOKEN: str class PasswordResetDoneView(PasswordContextMixin, TemplateView): title: Any -class PasswordResetConfirmView(PasswordContextMixin, FormView): +class PasswordResetConfirmView(PasswordContextMixin, FormView[BaseForm]): post_reset_login: bool post_reset_login_backend: Any reset_url_token: str @@ -65,7 +66,7 @@ class PasswordResetConfirmView(PasswordContextMixin, FormView): class PasswordResetCompleteView(PasswordContextMixin, TemplateView): title: Any -class PasswordChangeView(PasswordContextMixin, FormView): +class PasswordChangeView(PasswordContextMixin, FormView[BaseForm]): title: Any class PasswordChangeDoneView(PasswordContextMixin, TemplateView): diff --git a/django-stubs/contrib/contenttypes/admin.pyi b/django-stubs/contrib/contenttypes/admin.pyi index d19318806..e1b344a05 100644 --- a/django-stubs/contrib/contenttypes/admin.pyi +++ b/django-stubs/contrib/contenttypes/admin.pyi @@ -8,7 +8,7 @@ class GenericInlineModelAdminChecks(InlineModelAdminChecks): def _check_exclude_of_parent_model(self, obj: GenericInlineModelAdmin, parent_model: type[Model]) -> list[Any]: ... def _check_relation(self, obj: GenericInlineModelAdmin, parent_model: type[Model]) -> list[Any]: ... -class GenericInlineModelAdmin(InlineModelAdmin): +class GenericInlineModelAdmin(InlineModelAdmin[Model, Model]): template: str class GenericStackedInline(GenericInlineModelAdmin): ... diff --git a/django-stubs/contrib/contenttypes/fields.pyi b/django-stubs/contrib/contenttypes/fields.pyi index effb917c0..36350d3e1 100644 --- a/django-stubs/contrib/contenttypes/fields.pyi +++ b/django-stubs/contrib/contenttypes/fields.pyi @@ -63,7 +63,7 @@ class GenericRel(ForeignObjectRel): limit_choices_to: dict[str, Any] | Callable[[], Any] | None = ..., ) -> None: ... -class GenericRelation(ForeignObject): +class GenericRelation(ForeignObject[Any, Any]): rel_class: Any mti_inherited: bool object_id_field_name: str diff --git a/django-stubs/contrib/gis/feeds.pyi b/django-stubs/contrib/gis/feeds.pyi index b5274bf7f..08e5d2664 100644 --- a/django-stubs/contrib/gis/feeds.pyi +++ b/django-stubs/contrib/gis/feeds.pyi @@ -2,6 +2,7 @@ from collections.abc import Iterable, Sequence from typing import Any from django.contrib.syndication.views import Feed as BaseFeed +from django.db.models import Model from django.utils.feedgenerator import Atom1Feed, Rss201rev2Feed from django.utils.xmlutils import SimplerXMLGenerator @@ -18,4 +19,4 @@ class GeoAtom1Feed(Atom1Feed, GeoFeedMixin): ... class W3CGeoFeed(Rss201rev2Feed, GeoFeedMixin): def rss_attributes(self) -> dict[str, str]: ... -class Feed(BaseFeed): ... +class Feed(BaseFeed[Model, Any]): ... diff --git a/django-stubs/core/cache/__init__.pyi b/django-stubs/core/cache/__init__.pyi index cf25cd760..24f9ec317 100644 --- a/django-stubs/core/cache/__init__.pyi +++ b/django-stubs/core/cache/__init__.pyi @@ -8,7 +8,7 @@ from .backends.base import InvalidCacheBackendError as InvalidCacheBackendError DEFAULT_CACHE_ALIAS: str -class CacheHandler(BaseConnectionHandler): +class CacheHandler(BaseConnectionHandler[Any]): settings_name: str exception_class: type[Exception] def create_connection(self, alias: str) -> BaseCache: ... diff --git a/django-stubs/core/checks/registry.pyi b/django-stubs/core/checks/registry.pyi index 27b8f3f1a..0a456e8d5 100644 --- a/django-stubs/core/checks/registry.pyi +++ b/django-stubs/core/checks/registry.pyi @@ -34,8 +34,8 @@ class _ProcessedCheckCallable(Protocol[_C]): __call__: _C class CheckRegistry: - registered_checks: set[_ProcessedCheckCallable] - deployment_checks: set[_ProcessedCheckCallable] + registered_checks: set[_ProcessedCheckCallable[_CheckCallable]] + deployment_checks: set[_ProcessedCheckCallable[_CheckCallable]] def __init__(self) -> None: ... @overload def register(self, __check: _C) -> _ProcessedCheckCallable[_C]: ... @@ -50,7 +50,7 @@ class CheckRegistry: ) -> list[CheckMessage]: ... def tag_exists(self, tag: str, include_deployment_checks: bool = ...) -> bool: ... def tags_available(self, deployment_checks: bool = ...) -> set[str]: ... - def get_checks(self, include_deployment_checks: bool = ...) -> list[_ProcessedCheckCallable]: ... + def get_checks(self, include_deployment_checks: bool = ...) -> list[_ProcessedCheckCallable[_CheckCallable]]: ... registry: CheckRegistry = ... register = registry.register diff --git a/django-stubs/core/files/uploadedfile.pyi b/django-stubs/core/files/uploadedfile.pyi index 8a54c3c75..2a9c2ccbb 100644 --- a/django-stubs/core/files/uploadedfile.pyi +++ b/django-stubs/core/files/uploadedfile.pyi @@ -11,7 +11,7 @@ class UploadedFile(File[AnyStr]): name: str | None def __init__( self, - file: IO | None = ..., + file: IO[AnyStr] | None = ..., name: str | None = ..., content_type: str | None = ..., size: int | None = ..., @@ -34,7 +34,7 @@ class InMemoryUploadedFile(UploadedFile[AnyStr]): field_name: str | None def __init__( self, - file: IO, + file: IO[AnyStr], field_name: str | None, name: str | None, content_type: str | None, @@ -43,7 +43,7 @@ class InMemoryUploadedFile(UploadedFile[AnyStr]): content_type_extra: dict[str, str] = ..., ) -> None: ... -class SimpleUploadedFile(InMemoryUploadedFile): +class SimpleUploadedFile(InMemoryUploadedFile[AnyStr]): def __init__(self, name: str, content: bytes | None, content_type: str = ...) -> None: ... @classmethod def from_dict(cls: type[Self], file_dict: dict[str, str | bytes]) -> Self: ... diff --git a/django-stubs/core/files/uploadhandler.pyi b/django-stubs/core/files/uploadhandler.pyi index 4ea4351fb..b4c9256f2 100644 --- a/django-stubs/core/files/uploadhandler.pyi +++ b/django-stubs/core/files/uploadhandler.pyi @@ -49,7 +49,7 @@ class FileUploadHandler: def upload_interrupted(self) -> None: ... class TemporaryFileUploadHandler(FileUploadHandler): - file: TemporaryUploadedFile + file: TemporaryUploadedFile[Any] def new_file( self, field_name: str, diff --git a/django-stubs/core/management/commands/makemessages.pyi b/django-stubs/core/management/commands/makemessages.pyi index 9e4d08d64..83f2290be 100644 --- a/django-stubs/core/management/commands/makemessages.pyi +++ b/django-stubs/core/management/commands/makemessages.pyi @@ -3,7 +3,7 @@ from typing import Any, AnyStr from django.core.management.base import BaseCommand -plural_forms_re: Pattern[AnyStr] +plural_forms_re: Pattern[Any] STATUS_OK: int NO_LOCALE_DIR: Any diff --git a/django-stubs/core/management/utils.pyi b/django-stubs/core/management/utils.pyi index 6df277f66..bd1142e89 100644 --- a/django-stubs/core/management/utils.pyi +++ b/django-stubs/core/management/utils.pyi @@ -1,6 +1,6 @@ import os from collections.abc import Iterable, Sequence -from typing import Any +from typing import Any, AnyStr from django.apps.config import AppConfig from django.db.models.base import Model @@ -16,4 +16,4 @@ def get_random_secret_key() -> str: ... def parse_apps_and_model_labels(labels: Iterable[str]) -> tuple[set[type[Model]], set[AppConfig]]: ... def get_command_line_option(argv: Sequence[Any], option: Any) -> Any | None: ... def normalize_path_patterns(patterns: Iterable[str]) -> list[str]: ... -def is_ignored_path(path: str | os.PathLike, ignore_patterns: Iterable[str]) -> bool: ... +def is_ignored_path(path: str | os.PathLike[AnyStr], ignore_patterns: Iterable[str]) -> bool: ... diff --git a/django-stubs/core/paginator.pyi b/django-stubs/core/paginator.pyi index 97ad41499..061008ca5 100644 --- a/django-stubs/core/paginator.pyi +++ b/django-stubs/core/paginator.pyi @@ -12,7 +12,7 @@ class EmptyPage(InvalidPage): ... _T = TypeVar("_T") -class _SupportsPagination(Protocol[_T], Sized, Iterable): +class _SupportsPagination(Protocol[_T], Sized, Iterable[_T]): @overload def __getitem__(self, __index: int) -> _T: ... @overload diff --git a/django-stubs/db/models/fields/__init__.pyi b/django-stubs/db/models/fields/__init__.pyi index 3ca4ea49b..6c17562a3 100644 --- a/django-stubs/db/models/fields/__init__.pyi +++ b/django-stubs/db/models/fields/__init__.pyi @@ -181,7 +181,7 @@ class Field(RegisterLookupMixin, Generic[_ST, _GT]): def __get__(self: Self, instance: Any, owner: Any) -> Self: ... def deconstruct(self) -> Any: ... def set_attributes_from_name(self, name: str) -> None: ... - def db_type_parameters(self, connection: BaseDatabaseWrapper) -> DictWrapper: ... + def db_type_parameters(self, connection: BaseDatabaseWrapper) -> DictWrapper[Any]: ... def db_check(self, connection: BaseDatabaseWrapper) -> str | None: ... def db_type(self, connection: BaseDatabaseWrapper) -> str | None: ... def db_parameters(self, connection: BaseDatabaseWrapper) -> dict[str, str | None]: ... diff --git a/django-stubs/db/models/fields/files.pyi b/django-stubs/db/models/fields/files.pyi index 094a19cb8..446568801 100644 --- a/django-stubs/db/models/fields/files.pyi +++ b/django-stubs/db/models/fields/files.pyi @@ -33,7 +33,7 @@ class FieldFile(File[AnyStr]): class FileDescriptor(DeferredAttribute): field: FileField def __set__(self, instance: Model, value: Any | None) -> None: ... - def __get__(self, instance: Model | None, cls: type[Model] | None = ...) -> FieldFile | FileDescriptor: ... + def __get__(self, instance: Model | None, cls: type[Model] | None = ...) -> FieldFile[AnyStr] | FileDescriptor: ... _M = TypeVar("_M", bound=Model, contravariant=True) @@ -42,12 +42,12 @@ class _UploadToCallable(Protocol[_M]): class FileField(Field[Any, Any]): storage: Storage - upload_to: _PathCompatible | _UploadToCallable + upload_to: _PathCompatible | _UploadToCallable[Model] def __init__( self, verbose_name: _StrOrPromise | None = ..., name: str | None = ..., - upload_to: _PathCompatible | _UploadToCallable = ..., + upload_to: _PathCompatible | _UploadToCallable[_M] = ..., storage: Storage | Callable[[], Storage] | None = ..., *, max_length: int | None = ..., @@ -84,7 +84,7 @@ class ImageFileDescriptor(FileDescriptor): field: ImageField def __set__(self, instance: Model, value: str | None) -> None: ... -class ImageFieldFile(ImageFile, FieldFile): +class ImageFieldFile(ImageFile, FieldFile[AnyStr]): field: ImageField def delete(self, save: bool = ...) -> None: ... diff --git a/django-stubs/db/models/fields/json.pyi b/django-stubs/db/models/fields/json.pyi index 86e03ae9f..954e8f331 100644 --- a/django-stubs/db/models/fields/json.pyi +++ b/django-stubs/db/models/fields/json.pyi @@ -39,7 +39,7 @@ class HasAnyKeys(HasKeys): postgres_operator: str logical_operator: str -class JSONExact(lookups.Exact): ... +class JSONExact(lookups.Exact[Any]): ... class KeyTransform(Transform): key_name: str @@ -59,7 +59,7 @@ class CaseInsensitiveMixin: ... class KeyTransformIsNull(lookups.IsNull): ... class KeyTransformIn(lookups.In): ... class KeyTransformExact(JSONExact): ... -class KeyTransformIExact(CaseInsensitiveMixin, KeyTransformTextLookupMixin, lookups.IExact): ... +class KeyTransformIExact(CaseInsensitiveMixin, KeyTransformTextLookupMixin, lookups.IExact[Any]): ... class KeyTransformIContains(CaseInsensitiveMixin, KeyTransformTextLookupMixin, lookups.IContains): ... class KeyTransformStartsWith(KeyTransformTextLookupMixin, lookups.StartsWith): ... class KeyTransformIStartsWith(CaseInsensitiveMixin, KeyTransformTextLookupMixin, lookups.IStartsWith): ... @@ -68,10 +68,10 @@ class KeyTransformIEndsWith(CaseInsensitiveMixin, KeyTransformTextLookupMixin, l class KeyTransformRegex(KeyTransformTextLookupMixin, lookups.Regex): ... class KeyTransformIRegex(CaseInsensitiveMixin, KeyTransformTextLookupMixin, lookups.IRegex): ... class KeyTransformNumericLookupMixin: ... -class KeyTransformLt(KeyTransformNumericLookupMixin, lookups.LessThan): ... -class KeyTransformLte(KeyTransformNumericLookupMixin, lookups.LessThanOrEqual): ... -class KeyTransformGt(KeyTransformNumericLookupMixin, lookups.GreaterThan): ... -class KeyTransformGte(KeyTransformNumericLookupMixin, lookups.GreaterThanOrEqual): ... +class KeyTransformLt(KeyTransformNumericLookupMixin, lookups.LessThan[Any]): ... +class KeyTransformLte(KeyTransformNumericLookupMixin, lookups.LessThanOrEqual[Any]): ... +class KeyTransformGt(KeyTransformNumericLookupMixin, lookups.GreaterThan[Any]): ... +class KeyTransformGte(KeyTransformNumericLookupMixin, lookups.GreaterThanOrEqual[Any]): ... class KeyTransformFactory: key_name: Any diff --git a/django-stubs/db/models/fields/related_descriptors.pyi b/django-stubs/db/models/fields/related_descriptors.pyi index 752ead26c..50771fefa 100644 --- a/django-stubs/db/models/fields/related_descriptors.pyi +++ b/django-stubs/db/models/fields/related_descriptors.pyi @@ -56,11 +56,11 @@ class ReverseManyToOneDescriptor: field: ForeignKey[Any, Any] def __init__(self, rel: ManyToOneRel) -> None: ... @property - def related_manager_cls(self) -> type[RelatedManager]: ... + def related_manager_cls(self) -> type[RelatedManager[Model]]: ... def __get__(self, instance: Model | None, cls: type[Model] | None = ...) -> ReverseManyToOneDescriptor: ... def __set__(self, instance: Model, value: list[Model]) -> Any: ... -def create_reverse_many_to_one_manager(superclass: type, rel: Any) -> type[RelatedManager]: ... +def create_reverse_many_to_one_manager(superclass: type, rel: Any) -> type[RelatedManager[Model]]: ... class ManyToManyDescriptor(ReverseManyToOneDescriptor): field: ManyToManyField[Any, Any] # type: ignore[assignment] @@ -76,4 +76,4 @@ class ManyToManyDescriptor(ReverseManyToOneDescriptor): class _ForwardManyToManyManager(Generic[_T]): def all(self) -> QuerySet[Model]: ... -def create_forward_many_to_many_manager(superclass: type, rel: Any, reverse: Any) -> _ForwardManyToManyManager: ... +def create_forward_many_to_many_manager(superclass: type, rel: Any, reverse: Any) -> _ForwardManyToManyManager[Any]: ... diff --git a/django-stubs/db/models/fields/related_lookups.pyi b/django-stubs/db/models/fields/related_lookups.pyi index 6df8480c9..2a1d5585b 100644 --- a/django-stubs/db/models/fields/related_lookups.pyi +++ b/django-stubs/db/models/fields/related_lookups.pyi @@ -42,9 +42,9 @@ class RelatedLookupMixin: rhs: Any def get_prep_lookup(self) -> Any: ... -class RelatedExact(RelatedLookupMixin, Exact): ... -class RelatedLessThan(RelatedLookupMixin, LessThan): ... -class RelatedGreaterThan(RelatedLookupMixin, GreaterThan): ... -class RelatedGreaterThanOrEqual(RelatedLookupMixin, GreaterThanOrEqual): ... -class RelatedLessThanOrEqual(RelatedLookupMixin, LessThanOrEqual): ... +class RelatedExact(RelatedLookupMixin, Exact[Any]): ... +class RelatedLessThan(RelatedLookupMixin, LessThan[Any]): ... +class RelatedGreaterThan(RelatedLookupMixin, GreaterThan[Any]): ... +class RelatedGreaterThanOrEqual(RelatedLookupMixin, GreaterThanOrEqual[Any]): ... +class RelatedLessThanOrEqual(RelatedLookupMixin, LessThanOrEqual[Any]): ... class RelatedIsNull(RelatedLookupMixin, IsNull): ... diff --git a/django-stubs/db/models/fields/reverse_related.pyi b/django-stubs/db/models/fields/reverse_related.pyi index 349da5d61..6875130a3 100644 --- a/django-stubs/db/models/fields/reverse_related.pyi +++ b/django-stubs/db/models/fields/reverse_related.pyi @@ -23,7 +23,7 @@ class ForeignObjectRel(FieldCacheMixin): editable: bool is_relation: bool null: bool - field: ForeignObject + field: ForeignObject[Any, Any] model: type[Model] related_name: str | None related_query_name: str | None @@ -35,7 +35,7 @@ class ForeignObjectRel(FieldCacheMixin): field_name: str | None def __init__( self, - field: ForeignObject, + field: ForeignObject[Any, Any], to: type[Model] | str, related_name: str | None = ..., related_query_name: str | None = ..., @@ -48,7 +48,7 @@ class ForeignObjectRel(FieldCacheMixin): @property def name(self) -> str: ... @property - def remote_field(self) -> ForeignObject: ... + def remote_field(self) -> ForeignObject[Any, Any]: ... @property def target_field(self) -> AutoField[Any, Any]: ... @property diff --git a/django-stubs/db/models/lookups.pyi b/django-stubs/db/models/lookups.pyi index 03e743031..8b1ae1ab7 100644 --- a/django-stubs/db/models/lookups.pyi +++ b/django-stubs/db/models/lookups.pyi @@ -21,7 +21,7 @@ class Lookup(Generic[_T]): def __init__(self, lhs: Any, rhs: Any) -> None: ... def apply_bilateral_transforms(self, value: Expression) -> Expression: ... def batch_process_rhs( - self, compiler: SQLCompiler, connection: BaseDatabaseWrapper, rhs: OrderedSet | None = ... + self, compiler: SQLCompiler, connection: BaseDatabaseWrapper, rhs: OrderedSet[Any] | None = ... ) -> tuple[list[str], list[str]]: ... def get_source_expressions(self) -> list[Expression]: ... def set_source_expressions(self, new_exprs: list[Expression]) -> None: ... @@ -86,7 +86,7 @@ class IntegerFieldFloatRounding: class IntegerGreaterThanOrEqual(IntegerFieldFloatRounding, GreaterThanOrEqual[int | float]): ... class IntegerLessThan(IntegerFieldFloatRounding, LessThan[int | float]): ... -class In(FieldGetDbPrepValueIterableMixin, BuiltinLookup): +class In(FieldGetDbPrepValueIterableMixin, BuiltinLookup[str]): def split_parameter_list_as_sql(self, compiler: SQLCompiler, connection: BaseDatabaseWrapper) -> Any: ... class PatternLookup(BuiltinLookup[str]): diff --git a/django-stubs/db/models/manager.pyi b/django-stubs/db/models/manager.pyi index 8cfe86148..7195895a1 100644 --- a/django-stubs/db/models/manager.pyi +++ b/django-stubs/db/models/manager.pyi @@ -98,7 +98,7 @@ class BaseManager(Generic[_T]): params: Any = ..., translations: dict[str, str] | None = ..., using: str | None = ..., - ) -> RawQuerySet: ... + ) -> RawQuerySet[_T]: ... # The type of values may be overridden to be more specific in the mypy plugin, depending on the fields param def values(self, *fields: str | Combinable, **expressions: Any) -> ValuesQuerySet[_T, dict[str, Any]]: ... # The type of values_list may be overridden to be more specific in the mypy plugin, depending on the fields param @@ -157,10 +157,10 @@ class RelatedManager(Manager[_T]): def __call__(self, *, manager: str) -> RelatedManager[_T]: ... class ManagerDescriptor: - manager: BaseManager - def __init__(self, manager: BaseManager) -> None: ... + manager: BaseManager[Model] + def __init__(self, manager: BaseManager[Model]) -> None: ... @overload - def __get__(self, instance: None, cls: type[Model] | None = ...) -> BaseManager: ... + def __get__(self, instance: None, cls: type[Model] | None = ...) -> BaseManager[Model]: ... @overload def __get__(self, instance: Model, cls: type[Model] | None = ...) -> NoReturn: ... diff --git a/django-stubs/db/models/query.pyi b/django-stubs/db/models/query.pyi index fde8c3cfc..2b502a796 100644 --- a/django-stubs/db/models/query.pyi +++ b/django-stubs/db/models/query.pyi @@ -13,7 +13,7 @@ from typing_extensions import TypeAlias _T = TypeVar("_T", bound=Model, covariant=True) _Row = TypeVar("_Row", covariant=True) -_QS = TypeVar("_QS", bound=_QuerySet) +_QS = TypeVar("_QS", bound=_QuerySet[Model, Any]) _TupleT = TypeVar("_TupleT", bound=tuple[Any, ...], covariant=True) MAX_GET_RESULTS: int @@ -46,7 +46,7 @@ class FlatValuesListIterable(BaseIterable[_Row]): class _QuerySet(Generic[_T, _Row], Collection[_Row], Reversible[_Row], Sized): model: type[_T] query: Query - _iterable_class: type[BaseIterable] + _iterable_class: type[BaseIterable[Any]] def __init__( self, model: type[Model] | None = ..., @@ -126,7 +126,7 @@ class _QuerySet(Generic[_T, _Row], Collection[_Row], Reversible[_Row], Sized): params: Any = ..., translations: dict[str, str] | None = ..., using: str | None = ..., - ) -> RawQuerySet: ... + ) -> RawQuerySet[_T]: ... # The type of values may be overridden to be more specific in the mypy plugin, depending on the fields param def values(self, *fields: str | Combinable, **expressions: Any) -> _QuerySet[_T, dict[str, Any]]: ... # The type of values_list may be overridden to be more specific in the mypy plugin, depending on the fields param diff --git a/django-stubs/db/models/sql/constants.pyi b/django-stubs/db/models/sql/constants.pyi index 03fafcc03..839303fa7 100644 --- a/django-stubs/db/models/sql/constants.pyi +++ b/django-stubs/db/models/sql/constants.pyi @@ -1,5 +1,5 @@ from re import Pattern -from typing import AnyStr +from typing import AnyStr, TypeAlias from typing_extensions import Final, Literal @@ -10,7 +10,7 @@ SINGLE: Literal["single"] CURSOR: Literal["cursor"] NO_RESULTS: Literal["no results"] -ORDER_PATTERN: Pattern[AnyStr] +ORDER_PATTERN: TypeAlias = Pattern[AnyStr] ORDER_DIR: dict[str, tuple[str, str]] INNER: Literal["INNER JOIN"] diff --git a/django-stubs/db/models/sql/query.pyi b/django-stubs/db/models/sql/query.pyi index 09b74f139..a980e75c5 100644 --- a/django-stubs/db/models/sql/query.pyi +++ b/django-stubs/db/models/sql/query.pyi @@ -203,7 +203,7 @@ class JoinPromoter: negated: bool effective_connector: str num_children: int - votes: collections.Counter + votes: collections.Counter[Any] def __init__(self, connector: str, num_children: int, negated: bool) -> None: ... def add_votes(self, votes: Iterable[str]) -> None: ... def update_join_types(self, query: Query) -> set[str]: ... diff --git a/django-stubs/forms/forms.pyi b/django-stubs/forms/forms.pyi index 9150e2ab3..a4cad24e5 100644 --- a/django-stubs/forms/forms.pyi +++ b/django-stubs/forms/forms.pyi @@ -20,7 +20,7 @@ class BaseForm: use_required_attribute: bool is_bound: bool data: _DataT - files: _FilesT[AnyStr] + files: _FilesT[Any] auto_id: bool | str initial: Mapping[str, Any] error_class: type[ErrorList] diff --git a/django-stubs/forms/formsets.pyi b/django-stubs/forms/formsets.pyi index c3b91a302..bb3a112f4 100644 --- a/django-stubs/forms/formsets.pyi +++ b/django-stubs/forms/formsets.pyi @@ -39,7 +39,7 @@ class BaseFormSet(Generic[_F], Sized): prefix: str | None auto_id: str data: _DataT - files: _FilesT[AnyStr] + files: _FilesT[Any] initial: Sequence[Mapping[str, Any]] | None form_kwargs: dict[str, Any] error_class: type[ErrorList] diff --git a/django-stubs/forms/models.pyi b/django-stubs/forms/models.pyi index 4b3e7036c..7546b6b50 100644 --- a/django-stubs/forms/models.pyi +++ b/django-stubs/forms/models.pyi @@ -154,7 +154,7 @@ def modelformset_factory( model: type[_M], form: type[_ModelFormT] = ..., formfield_callback: _FormFieldCallback | None = ..., - formset: type[BaseModelFormSet] = ..., + formset: type[BaseModelFormSet[Model, ModelForm[Model]]] = ..., extra: int = ..., can_delete: bool = ..., can_order: bool = ..., @@ -200,7 +200,7 @@ def inlineformset_factory( parent_model: type[_ParentM], model: type[_M], form: type[_ModelFormT] = ..., - formset: type[BaseInlineFormSet] = ..., + formset: type[BaseInlineFormSet[_M, _ParentM, _ModelFormT]] = ..., fk_name: str | None = ..., fields: _Fields | None = ..., exclude: _Fields | None = ..., diff --git a/django-stubs/forms/utils.pyi b/django-stubs/forms/utils.pyi index 4ff83bc2a..be702dc3e 100644 --- a/django-stubs/forms/utils.pyi +++ b/django-stubs/forms/utils.pyi @@ -24,7 +24,7 @@ class ErrorDict(dict[Any, Any]): def as_ul(self) -> str: ... def as_text(self) -> str: ... -class ErrorList(UserList): +class ErrorList(UserList[Any]): data: list[ValidationError | str] error_class: str def __init__( diff --git a/django-stubs/http/request.pyi b/django-stubs/http/request.pyi index fa1044471..e75c1775d 100644 --- a/django-stubs/http/request.pyi +++ b/django-stubs/http/request.pyi @@ -33,7 +33,7 @@ class HttpRequest(BytesIO): POST: _ImmutableQueryDict COOKIES: dict[str, str] META: dict[str, Any] - FILES: MultiValueDict[str, uploadedfile.UploadedFile[AnyStr]] + FILES: MultiValueDict[str, uploadedfile.UploadedFile[Any]] path: str path_info: str method: str | None diff --git a/django-stubs/template/loader_tags.pyi b/django-stubs/template/loader_tags.pyi index f83385e47..242914dde 100644 --- a/django-stubs/template/loader_tags.pyi +++ b/django-stubs/template/loader_tags.pyi @@ -11,7 +11,7 @@ register: Any BLOCK_CONTEXT_KEY: str class BlockContext: - blocks: collections.defaultdict + blocks: collections.defaultdict[Any, Any] def __init__(self) -> None: ... def add_blocks(self, blocks: dict[str, BlockNode]) -> None: ... def pop(self, name: str) -> BlockNode: ... diff --git a/django-stubs/template/response.pyi b/django-stubs/template/response.pyi index 3e0a7760a..b0186cab0 100644 --- a/django-stubs/template/response.pyi +++ b/django-stubs/template/response.pyi @@ -53,7 +53,7 @@ class TemplateResponse(SimpleTemplateResponse): context_data: dict[str, Any] | None cookies: SimpleCookie[str] csrf_cookie_set: bool - json: functools.partial + json: functools.partial[Any] _request: HttpRequest status_code: int template_name: _TemplateForResponseT diff --git a/django-stubs/test/client.pyi b/django-stubs/test/client.pyi index 7f176427d..f29fc1b9a 100644 --- a/django-stubs/test/client.pyi +++ b/django-stubs/test/client.pyi @@ -20,8 +20,8 @@ from typing_extensions import TypeAlias BOUNDARY: str MULTIPART_CONTENT: str -CONTENT_TYPE_RE: Pattern[AnyStr] -JSON_CONTENT_TYPE_RE: Pattern[AnyStr] +CONTENT_TYPE_RE: TypeAlias = Pattern[AnyStr] +JSON_CONTENT_TYPE_RE: TypeAlias = Pattern[AnyStr] class RedirectCycleError(Exception): last_response: HttpResponseBase diff --git a/django-stubs/test/runner.pyi b/django-stubs/test/runner.pyi index 1dc405f75..65f7a18d7 100644 --- a/django-stubs/test/runner.pyi +++ b/django-stubs/test/runner.pyi @@ -6,6 +6,7 @@ from io import StringIO from typing import Any from unittest import TestCase, TestLoader, TestSuite, TextTestResult, TextTestRunner +from _typeshed import SupportsWrite from django.db.backends.base.base import BaseDatabaseWrapper from django.test.testcases import SimpleTestCase from django.test.utils import TimeKeeperProtocol @@ -31,7 +32,7 @@ class DebugSQLTextTestResult(TextTestResult): stream: Any def __init__(self, stream: Any, descriptions: bool, verbosity: int) -> None: ... debug_sql_stream: StringIO - handler: logging.StreamHandler + handler: logging.StreamHandler[SupportsWrite[str]] def startTest(self, test: TestCase) -> None: ... def stopTest(self, test: TestCase) -> None: ... def addError(self, test: Any, err: Any) -> None: ... @@ -165,7 +166,10 @@ def reorder_suite( suite: TestSuite, classes: tuple[type[TestCase], type[SimpleTestCase]], reverse: bool = ... ) -> TestSuite: ... def partition_suite_by_type( - suite: TestSuite, classes: tuple[type[TestCase], type[SimpleTestCase]], bins: list[OrderedSet], reverse: bool = ... + suite: TestSuite, + classes: tuple[type[TestCase], type[SimpleTestCase]], + bins: list[OrderedSet[Any]], + reverse: bool = ..., ) -> None: ... def partition_suite_by_case(suite: Any) -> list[Any]: ... def filter_tests_by_tags(suite: TestSuite, tags: set[str], exclude_tags: set[str]) -> TestSuite: ... diff --git a/django-stubs/test/testcases.pyi b/django-stubs/test/testcases.pyi index f720da137..1dc9898d3 100644 --- a/django-stubs/test/testcases.pyi +++ b/django-stubs/test/testcases.pyi @@ -13,7 +13,7 @@ from django.db import connections as connections # noqa: F401 from django.db.backends.base.base import BaseDatabaseWrapper from django.db.models.base import Model from django.db.models.query import QuerySet, RawQuerySet -from django.forms import BaseFormSet, Form +from django.forms import BaseForm, BaseFormSet, Form from django.forms.fields import EmailField from django.http import HttpRequest from django.http.response import FileResponse, HttpResponseBase @@ -120,7 +120,7 @@ class SimpleTestCase(unittest.TestCase): @overload def assertFormsetError( self, - formset: BaseFormSet, + formset: BaseFormSet[BaseForm], form_index: int | None, field: str | None, errors: list[str] | str, @@ -187,7 +187,7 @@ class TransactionTestCase(SimpleTestCase): serialized_rollback: bool def assertQuerysetEqual( self, - qs: Iterator[Any] | list[Model] | QuerySet[Model] | RawQuerySet, + qs: Iterator[Any] | list[Model] | QuerySet[Model] | RawQuerySet[Model], values: Collection[Any], transform: Callable[[Model], Any] | type[str] = ..., ordered: bool = ..., diff --git a/django-stubs/test/utils.pyi b/django-stubs/test/utils.pyi index 548f8cd80..9492b082b 100644 --- a/django-stubs/test/utils.pyi +++ b/django-stubs/test/utils.pyi @@ -135,9 +135,9 @@ class isolate_apps(TestContextDecorator): def extend_sys_path(*paths: str) -> Iterator[None]: ... @contextmanager def captured_output(stream_name: str) -> Iterator[StringIO]: ... -def captured_stdin() -> AbstractContextManager: ... -def captured_stdout() -> AbstractContextManager: ... -def captured_stderr() -> AbstractContextManager: ... +def captured_stdin() -> AbstractContextManager[Any]: ... +def captured_stdout() -> AbstractContextManager[Any]: ... +def captured_stderr() -> AbstractContextManager[Any]: ... @contextmanager def freeze_time(t: float) -> Iterator[None]: ... def tag(*tags: str) -> Callable[[_C], _C]: ... diff --git a/django-stubs/utils/decorators.pyi b/django-stubs/utils/decorators.pyi index 5bb0b7b0b..4c5c7b500 100644 --- a/django-stubs/utils/decorators.pyi +++ b/django-stubs/utils/decorators.pyi @@ -8,7 +8,7 @@ from django.views.generic.base import View _T = TypeVar("_T", bound=View | Callable[..., Any]) # Any callable _CallableType = TypeVar("_CallableType", bound=Callable[..., Any]) -class classonlymethod(classmethod): ... +class classonlymethod(classmethod[Any]): ... def method_decorator( decorator: Callable[..., Any] | Iterable[Callable[..., Any]], name: str = ... diff --git a/django-stubs/utils/termcolors.pyi b/django-stubs/utils/termcolors.pyi index 7e574e09b..b5d7e5a09 100644 --- a/django-stubs/utils/termcolors.pyi +++ b/django-stubs/utils/termcolors.pyi @@ -1,7 +1,7 @@ from collections.abc import Callable, Mapping, Sequence from typing import Any -color_names: Sequence +color_names: Sequence[Any] foreground: Mapping[str, str] background: Mapping[str, str] RESET: str diff --git a/django-stubs/utils/translation/__init__.pyi b/django-stubs/utils/translation/__init__.pyi index d8f063d54..3bca8fee9 100644 --- a/django-stubs/utils/translation/__init__.pyi +++ b/django-stubs/utils/translation/__init__.pyi @@ -13,7 +13,7 @@ class TranslatorCommentWarning(SyntaxWarning): ... class Trans: activate: Callable[..., Any] - check_for_language: functools._lru_cache_wrapper + check_for_language: functools._lru_cache_wrapper[Any] deactivate: Callable[..., Any] deactivate_all: Callable[..., Any] get_language: Callable[..., Any] diff --git a/django-stubs/views/generic/dates.pyi b/django-stubs/views/generic/dates.pyi index c73830bd4..78824622a 100644 --- a/django-stubs/views/generic/dates.pyi +++ b/django-stubs/views/generic/dates.pyi @@ -58,19 +58,19 @@ DatedItems: TypeAlias = tuple[_IndexableCollection[datetime.date] | None, _Index class BaseDateListView(MultipleObjectMixin[_M], DateMixin, View): date_list_period: str def get(self, request: HttpRequest, *args: Any, **kwargs: Any) -> HttpResponse: ... - def get_dated_items(self) -> DatedItems: ... + def get_dated_items(self) -> DatedItems[_M]: ... def get_ordering(self) -> str | Sequence[str]: ... def get_dated_queryset(self, **lookup: Any) -> models.query.QuerySet[_M]: ... def get_date_list_period(self) -> str: ... def get_date_list( - self, queryset: models.query.QuerySet, date_type: str | None = ..., ordering: str = ... - ) -> models.query.QuerySet: ... + self, queryset: models.query.QuerySet[_M], date_type: str | None = ..., ordering: str = ... + ) -> models.query.QuerySet[_M]: ... class BaseArchiveIndexView(BaseDateListView[_M]): context_object_name: str def get_dated_items(self) -> DatedItems[_M]: ... -class ArchiveIndexView(MultipleObjectTemplateResponseMixin, BaseArchiveIndexView): +class ArchiveIndexView(MultipleObjectTemplateResponseMixin, BaseArchiveIndexView[_M]): template_name_suffix: str class BaseYearArchiveView(YearMixin, BaseDateListView[_M]): @@ -79,38 +79,38 @@ class BaseYearArchiveView(YearMixin, BaseDateListView[_M]): def get_dated_items(self) -> DatedItems[_M]: ... def get_make_object_list(self) -> bool: ... -class YearArchiveView(MultipleObjectTemplateResponseMixin, BaseYearArchiveView): +class YearArchiveView(MultipleObjectTemplateResponseMixin, BaseYearArchiveView[_M]): template_name_suffix: str class BaseMonthArchiveView(YearMixin, MonthMixin, BaseDateListView[_M]): date_list_period: str def get_dated_items(self) -> DatedItems[_M]: ... -class MonthArchiveView(MultipleObjectTemplateResponseMixin, BaseMonthArchiveView): +class MonthArchiveView(MultipleObjectTemplateResponseMixin, BaseMonthArchiveView[_M]): template_name_suffix: str class BaseWeekArchiveView(YearMixin, WeekMixin, BaseDateListView[_M]): def get_dated_items(self) -> DatedItems[_M]: ... -class WeekArchiveView(MultipleObjectTemplateResponseMixin, BaseWeekArchiveView): +class WeekArchiveView(MultipleObjectTemplateResponseMixin, BaseWeekArchiveView[_M]): template_name_suffix: str class BaseDayArchiveView(YearMixin, MonthMixin, DayMixin, BaseDateListView[_M]): def get_dated_items(self) -> DatedItems[_M]: ... -class DayArchiveView(MultipleObjectTemplateResponseMixin, BaseDayArchiveView): +class DayArchiveView(MultipleObjectTemplateResponseMixin, BaseDayArchiveView[_M]): template_name_suffix: str class BaseTodayArchiveView(BaseDayArchiveView[_M]): def get_dated_items(self) -> DatedItems[_M]: ... -class TodayArchiveView(MultipleObjectTemplateResponseMixin, BaseTodayArchiveView): +class TodayArchiveView(MultipleObjectTemplateResponseMixin, BaseTodayArchiveView[_M]): template_name_suffix: str class BaseDateDetailView(YearMixin, MonthMixin, DayMixin, DateMixin, BaseDetailView[_M]): def get_object(self, queryset: QuerySet[_M] | None = ...) -> _M: ... -class DateDetailView(SingleObjectTemplateResponseMixin, BaseDateDetailView): +class DateDetailView(SingleObjectTemplateResponseMixin, BaseDateDetailView[_M]): template_name_suffix: str def timezone_today() -> datetime.date: ... diff --git a/django-stubs/views/generic/edit.pyi b/django-stubs/views/generic/edit.pyi index 7c024440a..3a6df41ed 100644 --- a/django-stubs/views/generic/edit.pyi +++ b/django-stubs/views/generic/edit.pyi @@ -10,7 +10,7 @@ from django.views.generic.detail import BaseDetailView, SingleObjectMixin, Singl from typing_extensions import Literal _FormT = TypeVar("_FormT", bound=BaseForm) -_ModelFormT = TypeVar("_ModelFormT", bound=BaseModelForm) +_ModelFormT = TypeVar("_ModelFormT", bound=BaseModelForm[models.Model]) _M = TypeVar("_M", bound=models.Model) class FormMixin(Generic[_FormT], ContextMixin): diff --git a/django-stubs/views/generic/list.pyi b/django-stubs/views/generic/list.pyi index e0271ea82..1494e9c7a 100644 --- a/django-stubs/views/generic/list.pyi +++ b/django-stubs/views/generic/list.pyi @@ -22,7 +22,7 @@ class MultipleObjectMixin(Generic[_M], ContextMixin): def get_ordering(self) -> str | Sequence[str] | None: ... def paginate_queryset( self, queryset: _SupportsPagination[_M], page_size: int - ) -> tuple[Paginator[_M], Page, _SupportsPagination[_M], bool]: ... + ) -> tuple[Paginator[_M], Page[_M], _SupportsPagination[_M], bool]: ... def get_paginate_by(self, queryset: _SupportsPagination[_M]) -> int | None: ... def get_paginator( self, From d6aba2e580f714b964787d736deb99bd16d2878c Mon Sep 17 00:00:00 2001 From: Christian Bundy Date: Tue, 24 Jan 2023 00:40:59 -0800 Subject: [PATCH 35/36] Fix TypeAlias import --- django-stubs/db/models/sql/constants.pyi | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/django-stubs/db/models/sql/constants.pyi b/django-stubs/db/models/sql/constants.pyi index 839303fa7..e217564a4 100644 --- a/django-stubs/db/models/sql/constants.pyi +++ b/django-stubs/db/models/sql/constants.pyi @@ -1,7 +1,7 @@ from re import Pattern -from typing import AnyStr, TypeAlias +from typing import AnyStr -from typing_extensions import Final, Literal +from typing_extensions import Final, Literal, TypeAlias GET_ITERATOR_CHUNK_SIZE: Final[int] From 9bcb79df54779025d1d7d16b6a55d3c9c6118fe6 Mon Sep 17 00:00:00 2001 From: Christian Bundy Date: Tue, 24 Jan 2023 00:50:48 -0800 Subject: [PATCH 36/36] HACK: Make mypy-test.ini to avoid changing tests --- mypy-test.ini | 28 ++++++++++++++++++++++++++++ pytest.ini | 2 +- 2 files changed, 29 insertions(+), 1 deletion(-) create mode 100644 mypy-test.ini diff --git a/mypy-test.ini b/mypy-test.ini new file mode 100644 index 000000000..e86b2f17e --- /dev/null +++ b/mypy-test.ini @@ -0,0 +1,28 @@ +# Regular configuration file (can be used as base in other projects, runs in CI) + +[mypy] +allow_redefinition = True +check_untyped_defs = True +ignore_missing_imports = True +incremental = True +strict_optional = True +show_traceback = True +warn_no_return = False +warn_unused_ignores = True +warn_redundant_casts = True +warn_unused_configs = True +warn_unreachable = True +disallow_untyped_defs = true +disallow_incomplete_defs = true +disallow_any_generics = false + +plugins = + mypy_django_plugin.main + +# Ignore incomplete hints in yaml-stubs +[mypy-yaml.*] +disallow_untyped_defs = false +disallow_incomplete_defs = false + +[mypy.plugins.django-stubs] +django_settings_module = scripts.django_tests_settings diff --git a/pytest.ini b/pytest.ini index 53d518433..26b0086eb 100644 --- a/pytest.ini +++ b/pytest.ini @@ -7,5 +7,5 @@ addopts = -s -v --cache-clear - --mypy-ini-file=mypy.ini + --mypy-ini-file=mypy-test.ini --mypy-extension-hook=scripts.tests_extension_hook.django_plugin_hook