mirror of
https://github.com/davidhalter/django-stubs.git
synced 2025-12-07 04:34:29 +08:00
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:
@@ -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]: ...
|
||||
|
||||
10
test-data/typecheck/queryset.test
Normal file
10
test-data/typecheck/queryset.test
Normal 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]
|
||||
Reference in New Issue
Block a user