QuerySet.in_bulk fixes.

- Made id_list of type Sequence[Any], rather than Any, according to mkurnikov's review.
- Removed **kwargs.
- Made returned Dict keys of type Any rather than int or str as it depends on the provided field's type.
- Added test with examples from Django docs.
This commit is contained in:
Seth Yastrov
2019-02-22 08:10:53 +01:00
parent cda703a94b
commit 3b8c5d08e8
2 changed files with 11 additions and 3 deletions

View File

@@ -84,9 +84,7 @@ class QuerySet(Iterable[_T], Sized):
def latest(self, *fields: Any, field_name: Optional[Any] = ...) -> _T: ...
def first(self) -> Optional[_T]: ...
def last(self) -> Optional[_T]: ...
def in_bulk(
self, id_list: Any = ..., *, field_name: str = ..., **kwargs: Any
) -> Dict[Union[int, str], _T]: ...
def in_bulk(self, id_list: Sequence[Any] = ..., *, field_name: str = ...) -> Dict[Any, _T]: ...
def delete(self) -> Tuple[int, Dict[str, int]]: ...
def update(self, **kwargs: Any) -> int: ...
def _update(self, values: Any) -> Optional[Any]: ...

View File

@@ -0,0 +1,10 @@
[CASE test_queryset]
from django.db import models
class Blog(models.Model):
slug = models.CharField(max_length=100)
reveal_type(Blog.objects.in_bulk([1])) # E: Revealed type is 'builtins.dict[Any, main.Blog*]'
reveal_type(Blog.objects.in_bulk()) # E: Revealed type is 'builtins.dict[Any, main.Blog*]'
reveal_type(Blog.objects.in_bulk(['beatles_blog'], field_name='slug')) # E: Revealed type is 'builtins.dict[Any, main.Blog*]'
[out]