ITADN

[6.0.3 regression] Wrong type for slice of annotated `values_list` query

#3381Openandersk 创建于 2026-05-12
bug
A
anderskcommented
This worked in 6.0.2 and fails in 6.0.3. ```python from typing import Iterable from django.db.models import Model, F class Foo(Model): pass def get_foo_ids() -> Iterable[int]: return Foo.objects.all().annotate(a=F("id")).values_list("id", flat=True)[:] ``` 6.0.2 correctly types the slice as `QuerySet[Foo@AnnotatedWith[…], int]`, but 6.0.3 incorrectly types it as `QuerySet[Foo@AnnotatedWith[…], Foo@AnnotatedWith[…]]`. Full error from 6.0.3: ``` my_app/models.py:8: error: Incompatible return value type (got "QuerySet[Foo@AnnotatedWith[TypedDict({'a': Any})], Foo@AnnotatedWith[TypedDict({'a': Any})]]", expected "Iterable[int]") [return-value] Found 1 error in 1 file (checked 3 source files) ``` I bisected the problem to - 7da3047575469282c2536b8248eff89a423288d5 (#3266, cc @UnknownPlatypus)
0 条评论