Repository navigation
Type prefetch_related lookups and infer Prefetch models - #426
Merged
kodiakhq[bot] merged 2 commits intoOct 14, 2026
Merged
Conversation
kalekseev
force-pushed
the
feat/typed-prefetch-related
branch
from
October 11, 2026 11:43
93f7042 to
7444998
Compare
kalekseev
marked this pull request as ready for review
October 11, 2026 11:45
Author
|
@sbdchd ready for review |
UnknownPlatypus
added a commit
to UnknownPlatypus/django-stubs
that referenced
this pull request
Nov 11, 2026
# I have made things! While triaging the merged [django-types](https://github.com/sbdchd/django-types) PRs, many turned out to be already fixed here, but nothing ran the behaviour through pyright, pyrefly and ty, and some of it had no test at all. This adds those tests, with no stub changes: - `prefetch_related()` overloads and `Prefetch.queryset` - managers not supporting `len()`, indexing or `delete()` like querysets - `execute_wrapper()` and `constraint_checks_disabled()` as context managers - the async queryset methods (`aget`, `afirst`, `acreate`, `aiterator`, `async for`) - `upload_to` callables taking `(instance, filename)` - `User.objects` as `UserManager[User]` - `admin.register()` keeping the admin subclass, and the admin action/display decorators keeping the signature - `AdminSite.get_model_admin()` and `LogEntry.objects.log_actions()` overloads - `formset_factory()`, `@receiver`, `@deconstructible`, `keep_lazy_text`, the cache view decorators and `request.headers` ## Related issues Tests proposed while triaging sbdchd#426, sbdchd#425, sbdchd#420, sbdchd#405, sbdchd#350, sbdchd#330, sbdchd#310, sbdchd#308, sbdchd#288, sbdchd#262, sbdchd#238, sbdchd#120, sbdchd#119, sbdchd#105, sbdchd#42, sbdchd#37, sbdchd#8, sbdchd#2. ## AI Policy - [ ] I have read and agree to the [AI Policy](https://github.com/typeddjango/django-stubs/blob/master/.github/AI_POLICY.md), removed any "Co-Authored-By" lines attributing coding agents, and manually reviewed the final result
1 task done
UnknownPlatypus
added a commit
to typeddjango/django-stubs
that referenced
this pull request
Nov 11, 2026
# I have made things! While triaging the merged [django-types](https://github.com/sbdchd/django-types) PRs, many turned out to be already fixed here, but nothing ran the behaviour through pyright, pyrefly and ty, and some of it had no test at all. This adds those tests, with no stub changes: - `prefetch_related()` overloads and `Prefetch.queryset` - managers not supporting `len()`, indexing or `delete()` like querysets - `execute_wrapper()` and `constraint_checks_disabled()` as context managers - the async queryset methods (`aget`, `afirst`, `acreate`, `aiterator`, `async for`) - `upload_to` callables taking `(instance, filename)` - `User.objects` as `UserManager[User]` - `admin.register()` keeping the admin subclass, and the admin action/display decorators keeping the signature - `AdminSite.get_model_admin()` and `LogEntry.objects.log_actions()` overloads - `formset_factory()`, `@receiver`, `@deconstructible`, `keep_lazy_text`, the cache view decorators and `request.headers` ## Related issues Tests proposed while triaging sbdchd#426, sbdchd#425, sbdchd#420, sbdchd#405, sbdchd#350, sbdchd#330, sbdchd#310, sbdchd#308, sbdchd#288, sbdchd#262, sbdchd#238, sbdchd#120, sbdchd#119, sbdchd#105, sbdchd#42, sbdchd#37, sbdchd#8, sbdchd#2. ## AI Policy - [ ] I have read and agree to the [AI Policy](https://github.com/typeddjango/django-stubs/blob/master/.github/AI_POLICY.md), removed any "Co-Authored-By" lines attributing coding agents, and manually reviewed the final result
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
QuerySet.prefetch_relatedandManager.prefetch_relatedacceptstr | Prefetchlookups, plus the positionalNoneoverload that clears prefetches. They keep the queryset return type.Prefetchinfers its model from itsquerysetargument and defaults toAnywithout one.Prefetch.querysetis nullable, matching runtime.