Repository navigation
Fix queryset variance and enum choices compatibility with ty - #412
Merged
Merged
Conversation
Preserve QuerySet covariance with documented, method-specific ignores and correct __class_getitem__ to return type[Self]. Use nullable field TypeVar defaults to work around astral-sh/ty#4551 while preserving bare custom CharField and IntegerField subclasses. Add fixtures checked by ty, Pyright, and mypy covering enum choices, field value types, and nullable custom fields with default=None and db_default=None. Update the locked ty version to 0.0.82 so CI exercises the regression. Validation: CI=1 ./s/lint (33 tests; mypy 2.1.0, Pyright 1.1.410, ty 0.0.82), focused fixtures with ty --error-on-warning, and uv lock --check --offline. The new nullable custom-field cases fail on the previous PR commit in all three checkers and pass with the nullable TypeVar defaults.
kalekseev
force-pushed
the
codex/ty-compatibility
branch
from
September 26, 2026 05:43
8ed714b to
8f85098
Compare
1 task done
UnknownPlatypus
added a commit
to typeddjango/django-stubs
that referenced
this pull request
Nov 5, 2026
At runtime `QuerySet.__class_getitem__` returns `cls`, but the stub returned an instance. Same signature as `BaseManager.__class_getitem__`. Ported from sbdchd#412
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.
Fix queryset variance diagnostics and enum choices inference in ty. Preserve nullable custom field subclasses by including
Nonein the field TypeVar defaults, and correctQuerySet.__class_getitem__to returntype[Self].Add fixtures checked by ty, Pyright, and mypy for enum choices and bare
CharField/IntegerFieldsubclasses usingnull=Truewithdefault=Noneordb_default=None. Update the locked ty version to 0.0.82.Validation:
CI=1 ./s/lint(33 tests; Ruff, mypy 2.1.0, Pyright 1.1.410, ty 0.0.82), focused fixtures with ty--error-on-warning, anduv lock --check --offline. The new nullable subclass cases fail on the previous PR commit in all three checkers and pass with this fix.