mypy: Remove use of ValuesQuerySet and QuerySetAny.

This was made unnecessary in django-stubs 5.0.1 and mypy 1.10.

Signed-off-by: Anders Kaseorg <anders@zulip.com>
This commit is contained in:
Anders Kaseorg
2024-08-24 17:30:41 -07:00
parent f4d98b03d5
commit 8c0b2d14aa
12 changed files with 24 additions and 39 deletions

View File

@@ -128,24 +128,18 @@ needing to do an explicit annotation.
When declaring the types for functions that accept a `QuerySet`
object, you should always supply the model type that it accepts as the
type parameter.
first type parameter.
```python
def foo(user: QuerySet[UserProfile]) -> None:
...
```
In cases where you need to type the return value from `.values_list`
or `.values` on a `QuerySet`, you can use the special
`django_stubs_ext.ValuesQuerySet` type.
For `.values_list`, the second type parameter will be the type of the
column.
For `.values_list`, supply the type of the column as the second type
parameter.
```python
from django_stubs_ext import ValuesQuerySet
def get_book_page_counts() -> ValuesQuerySet[Book, int]:
def get_book_page_counts() -> QuerySet[Book, int]:
return Book.objects.filter().values_list("page_count", flat=True)
```
@@ -153,15 +147,13 @@ For `.values`, we prefer to define a `TypedDict` containing the
key-value pairs for the columns.
```python
from django_stubs_ext import ValuesQuerySet
class BookMetadata(TypedDict):
id: int
name: str
def get_book_meta_data(
book_ids: List[int],
) -> ValuesQuerySet[Book, BookMetadata]:
) -> QuerySet[Book, BookMetadata]:
return Book.objects.filter(id__in=book_ids).values("name", "id")
```