Skip to content

Fix queryset variance and enum choices compatibility with ty - #412

Merged
kodiakhq[bot] merged 1 commit into
sbdchd:mainfrom
kalekseev:codex/ty-compatibility
Sep 26, 2026
Merged

kodiakhq[bot] merged 1 commit into
sbdchd:mainfrom
kalekseev:codex/ty-compatibility

Conversation

@kalekseev

@kalekseev kalekseev commented Sep 25, 2026 •

Copy link
Copy Markdown

Fix queryset variance diagnostics and enum choices inference in ty. Preserve nullable custom field subclasses by including None in the field TypeVar defaults, and correct QuerySet.__class_getitem__ to return type[Self].

Add fixtures checked by ty, Pyright, and mypy for enum choices and bare CharField/IntegerField subclasses using null=True with default=None or db_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, and uv lock --check --offline. The new nullable subclass cases fail on the previous PR commit in all three checkers and pass with this fix.

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
kalekseev force-pushed the codex/ty-compatibility branch from 8ed714b to 8f85098 Compare September 26, 2026 05:43

@sbdchd sbdchd left a comment

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

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

Thanks!

@kodiakhq
kodiakhq Bot merged commit 2949da9 into sbdchd:main Sep 26, 2026
2 checks passed
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
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants