From fefc54f86a44da1a72f166c23200d5d27c5eb5f2 Mon Sep 17 00:00:00 2001 From: Matthew Foster Walsh <15671892+mfosterw@users.noreply.github.com> Date: Wed, 14 Feb 2024 06:32:59 -0500 Subject: [PATCH] Add through_defaults for RelatedManager methods (#1943) * Add through_defaults for RelatedManager methods * Use ... for defaults --- .../db/models/fields/related_descriptors.pyi | 22 +++++++++++++++---- tests/typecheck/fields/test_related.yml | 2 +- 2 files changed, 19 insertions(+), 5 deletions(-) diff --git a/django-stubs/db/models/fields/related_descriptors.pyi b/django-stubs/db/models/fields/related_descriptors.pyi index 9daa7ba53..e5bda5cd1 100644 --- a/django-stubs/db/models/fields/related_descriptors.pyi +++ b/django-stubs/db/models/fields/related_descriptors.pyi @@ -135,12 +135,26 @@ class ManyToManyDescriptor(ReverseManyToOneDescriptor, Generic[_To, _Through]): @type_check_only class ManyRelatedManager(Manager[_M], Generic[_M]): related_val: tuple[int, ...] - def add(self, *objs: _M | int, bulk: bool = ...) -> None: ... - async def aadd(self, *objs: _M | int, bulk: bool = ...) -> None: ... + def add(self, *objs: _M | int, bulk: bool = ..., through_defaults: dict[str, Any] | None = ...) -> None: ... + async def aadd(self, *objs: _M | int, bulk: bool = ..., through_defaults: dict[str, Any] | None = ...) -> None: ... def remove(self, *objs: _M | int, bulk: bool = ...) -> None: ... async def aremove(self, *objs: _M | int, bulk: bool = ...) -> None: ... - def set(self, objs: QuerySet[_M] | Iterable[_M | int], *, bulk: bool = ..., clear: bool = ...) -> None: ... - async def aset(self, objs: QuerySet[_M] | Iterable[_M | int], *, bulk: bool = ..., clear: bool = ...) -> None: ... + def set( + self, + objs: QuerySet[_M] | Iterable[_M | int], + *, + bulk: bool = ..., + clear: bool = ..., + through_defaults: dict[str, Any] | None = ..., + ) -> None: ... + async def aset( + self, + objs: QuerySet[_M] | Iterable[_M | int], + *, + bulk: bool = ..., + clear: bool = ..., + through_defaults: dict[str, Any] | None = ..., + ) -> None: ... def clear(self) -> None: ... async def aclear(self) -> None: ... def __call__(self, *, manager: str) -> ManyRelatedManager[_M]: ... diff --git a/tests/typecheck/fields/test_related.yml b/tests/typecheck/fields/test_related.yml index 99de4ddbd..ba4512652 100644 --- a/tests/typecheck/fields/test_related.yml +++ b/tests/typecheck/fields/test_related.yml @@ -1134,7 +1134,7 @@ main:26: note: Revealed type is "myapp.models.MyModel_auto_through" main:28: note: Revealed type is "builtins.str" main:29: note: Revealed type is "builtins.str" - main:30: note: Revealed type is "def (*objs: Union[myapp.models.MyModel, builtins.int], bulk: builtins.bool =)" + main:30: note: Revealed type is "def (*objs: Union[myapp.models.MyModel, builtins.int], bulk: builtins.bool =, through_defaults: Union[builtins.dict[builtins.str, Any], None] =)" installed_apps: - myapp files: