-
-
Notifications
You must be signed in to change notification settings - Fork 456
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
ValuesQuerySet is removed and not available #144
Comments
I meant it to be stubs-only class, maybe I should've start it with If it's not, then I guess the only way is to go back to the multi-parameter generics then... Support of the |
That's my attempt: import typing
if typing.TYPE_CHECKING:
from django.db.models.query import ValuesQuerySet
def test() -> 'ValuesQuerySet[BlogPost]':
return BlogPost.objects.all().values_list('id', flat=True) Output:
I was not sure about the second argument. And I have tried def test() -> 'ValuesQuerySet[BlogPost, int]':
return BlogPost.objects.all().values_list('id', flat=True) And it worked. |
Yes, this is kind of what I expected users to be doing. I wanted to make Actually, for your case, in the wild, if you're going to return We do need to add some docs for it, though. |
I have get away with this code in my case: if typing.TYPE_CHECKING:
from django.db.models.query import ValuesQuerySet
else:
from typing import Dict as ValuesQuerySet
ENUM_CHOICES: ValuesQuerySet[AssetType, Tuple[str, str]] = AssetType.objects.values_list("name", "value") But I consider it a very dirty hack. |
I tried with from django.db import Model
from typing import Any, Dict, TypeAlias
ValuesQuerySet: TypeAlias[Model, Dict[str, Any]] = Dict Is workings as expected for now, donno if is the best alternative but it's checking the argument types |
I found
Using that the following works: from django_stubs_ext.aliases import ValuesQuerySet
def foo() -> ValuesQuerySet[MyModel, dict[str, Any]]:
return MyModel.objects.values('field_one', 'field_two', 'another_field') |
Indeed as @mschoettle mentions, this has been solved for a long time, it has been publicly exported from And |
…ypeddjango#236) Closes typeddjango#144 This seems straightforward, but I'm not writing a lot of .pyi files. I have tested it briefly and it seems to work.
I have tried to use
ValuesQuerySet
that is returned in:Reproduction link: https://github.com/sobolevn/django_stubs_example/blob/master/server/apps/main/logic/repo.py
Output:
But, it looks like
ValuesQuerySet
is removed in1.9
, and there's not such class: https://github.com/django/django/blob/aed89adad54a977829c4f180b036033e031ebcc7/docs/releases/1.9.txt#L1069So, it is not clear how to annotate your function to return
ValuesQuerySet
when it is missing from django.The text was updated successfully, but these errors were encountered: