Skip to content

Commit e52d59d

Browse files
update / create defaults are read-only Mapping (#12)
this allows a calling method to use a more specific TypedDict for instance the underlying code does not mutate these, MutableMapping seems to be a leftover from when this was Dict[str, Any] Co-authored-by: Anthony Sottile <[email protected]>
1 parent b666d14 commit e52d59d

File tree

2 files changed

+14
-18
lines changed

2 files changed

+14
-18
lines changed

django-stubs/db/models/manager.pyi

Lines changed: 7 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import datetime
2-
from collections.abc import AsyncIterator, Callable, Collection, Iterable, Iterator, MutableMapping, Sequence
2+
from collections.abc import AsyncIterator, Callable, Collection, Iterable, Iterator, Mapping, Sequence
33
from typing import Any, Generic, NoReturn, TypeVar, overload
44

55
from django.db.models.base import Model
@@ -63,20 +63,18 @@ class BaseManager(Generic[_T]):
6363
) -> list[_T]: ...
6464
def bulk_update(self, objs: Iterable[_T], fields: Sequence[str], batch_size: int | None = ...) -> int: ...
6565
async def abulk_update(self, objs: Iterable[_T], fields: Sequence[str], batch_size: int | None = ...) -> int: ...
66-
def get_or_create(self, defaults: MutableMapping[str, Any] | None = ..., **kwargs: Any) -> tuple[_T, bool]: ...
67-
async def aget_or_create(
68-
self, defaults: MutableMapping[str, Any] | None = ..., **kwargs: Any
69-
) -> tuple[_T, bool]: ...
66+
def get_or_create(self, defaults: Mapping[str, Any] | None = ..., **kwargs: Any) -> tuple[_T, bool]: ...
67+
async def aget_or_create(self, defaults: Mapping[str, Any] | None = ..., **kwargs: Any) -> tuple[_T, bool]: ...
7068
def update_or_create(
7169
self,
72-
defaults: MutableMapping[str, Any] | None = ...,
73-
create_defaults: MutableMapping[str, Any] | None = ...,
70+
defaults: Mapping[str, Any] | None = ...,
71+
create_defaults: Mapping[str, Any] | None = ...,
7472
**kwargs: Any,
7573
) -> tuple[_T, bool]: ...
7674
async def aupdate_or_create(
7775
self,
78-
defaults: MutableMapping[str, Any] | None = ...,
79-
create_defaults: MutableMapping[str, Any] | None = ...,
76+
defaults: Mapping[str, Any] | None = ...,
77+
create_defaults: Mapping[str, Any] | None = ...,
8078
**kwargs: Any,
8179
) -> tuple[_T, bool]: ...
8280
def earliest(self, *fields: str | OrderBy) -> _T: ...

django-stubs/db/models/query.pyi

Lines changed: 7 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import datetime
2-
from collections.abc import AsyncIterator, Collection, Iterable, Iterator, MutableMapping, Sequence, Sized
2+
from collections.abc import AsyncIterator, Collection, Iterable, Iterator, Mapping, Sequence, Sized
33
from typing import Any, Generic, NamedTuple, overload
44

55
from django.db.backends.utils import _ExecuteQuery
@@ -97,20 +97,18 @@ class QuerySet(Generic[_Model, _Row], Iterable[_Row], Sized):
9797
async def abulk_update(
9898
self, objs: Iterable[_Model], fields: Iterable[str], batch_size: int | None = ...
9999
) -> int: ...
100-
def get_or_create(self, defaults: MutableMapping[str, Any] | None = ..., **kwargs: Any) -> tuple[_Model, bool]: ...
101-
async def aget_or_create(
102-
self, defaults: MutableMapping[str, Any] | None = ..., **kwargs: Any
103-
) -> tuple[_Model, bool]: ...
100+
def get_or_create(self, defaults: Mapping[str, Any] | None = ..., **kwargs: Any) -> tuple[_Model, bool]: ...
101+
async def aget_or_create(self, defaults: Mapping[str, Any] | None = ..., **kwargs: Any) -> tuple[_Model, bool]: ...
104102
def update_or_create(
105103
self,
106-
defaults: MutableMapping[str, Any] | None = ...,
107-
create_defaults: MutableMapping[str, Any] | None = ...,
104+
defaults: Mapping[str, Any] | None = ...,
105+
create_defaults: Mapping[str, Any] | None = ...,
108106
**kwargs: Any,
109107
) -> tuple[_Model, bool]: ...
110108
async def aupdate_or_create(
111109
self,
112-
defaults: MutableMapping[str, Any] | None = ...,
113-
create_defaults: MutableMapping[str, Any] | None = ...,
110+
defaults: Mapping[str, Any] | None = ...,
111+
create_defaults: Mapping[str, Any] | None = ...,
114112
**kwargs: Any,
115113
) -> tuple[_Model, bool]: ...
116114
def earliest(self, *fields: str | OrderBy) -> _Row: ...

0 commit comments

Comments
 (0)