Skip to content

Commit

Permalink
Add through_defaults for RelatedManager methods (#1943)
Browse files Browse the repository at this point in the history
* Add through_defaults for RelatedManager methods

* Use ... for defaults
  • Loading branch information
mfosterw authored Feb 14, 2024
1 parent 2faa8be commit fefc54f
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 5 deletions.
22 changes: 18 additions & 4 deletions django-stubs/db/models/fields/related_descriptors.pyi
Original file line number Diff line number Diff line change
Expand Up @@ -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]: ...
Expand Down
2 changes: 1 addition & 1 deletion tests/typecheck/fields/test_related.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down

0 comments on commit fefc54f

Please sign in to comment.