Initial support for to_attr
inferrence in Prefetch
calls
#2779
+237
−1
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
I have made things!
A bit more involved than I expected. I was close to reuse some mypy plugin utils for the argument inference but they currently do no support class instantiation so I've adapted from it.
The logic is very similar to what is done in the
.annotate()
plugin code.I left a few todos for improvements in later PR's, this one is already quite big.
todos
Correctly handle mixed
annotate
/prefetch_related
on the same key -- ✅ in #2791Currently it applies the last annotation, in reality, only the annotate matter and the prefetch is ignored + we should probably raise type errors?
Narrow type when no queryset is provided -- ✅ in #2786
Using the existing lookup_type infrastructure.
get_model_info_from_qs_ctx
_extract_model_type_from_queryset
Related issues
Fixes #795