Skip to content
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

Improve types for QuerySet.contains and bulk_create #1134

Merged
merged 2 commits into from
Aug 28, 2022

Conversation

adamchainz
Copy link
Contributor

I have made things!

Copying in review from #1131.

Related issues

n/a

Comment on lines +113 to +114
def contains(self, obj: models.Model) -> bool: ...
async def acontains(self, obj: models.Model) -> bool: ...
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

using _T here gave me:

django-stubs/db/models/query.pyi:113: error: Cannot use a covariant type variable as a parameter
django-stubs/db/models/query.pyi:114: error: Cannot use a covariant type variable as a parameter

But looking at the source, it seems any instance of a model class is acceptable:

https://github.com/django/django/blob/b92ffebb0cdc469baaf1b8f0e72dddb069eb2fb4/django/db/models/query.py#L1241-L1255

hence change to models.Model

Copy link
Member

@sobolevn sobolevn left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Wow, update_conflicts=True looks like an amazing feature!

@adamchainz
Copy link
Contributor Author

Yeah!

I suppose for strict accuracy, we could use @overload to enforce that ignore_conflicts and update_conflicts are not passed at the same time, and that the fields are passed if update_conflicts is True, etc. But I cba to enumerate all the cases right now 😅

@sobolevn sobolevn merged commit 3622a61 into typeddjango:master Aug 28, 2022
@adamchainz adamchainz deleted the fix_queryset branch August 28, 2022 08:37
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

Successfully merging this pull request may close these issues.

2 participants