Repository navigation
[ty] Validate free type variables in ClassVar annotations - #29132
Draft
charliermarsh wants to merge 8 commits into
Draft
charliermarsh wants to merge 8 commits into
charliermarsh wants to merge 8 commits into
Conversation
charliermarsh
added this pull request to stack #29134
October 6, 2026 14:16
charliermarsh
marked this pull request as draft
October 6, 2026 14:17
Typing conformance resultsNo changes detected ✅Current numbersThe percentage of diagnostics emitted that were expected errors held steady at 98.24%. The percentage of expected errors that received a diagnostic held steady at 98.24%. The number of fully passing files held steady at 134/146. |
Memory usage reportSummary
Significant changesClick to expand detailed breakdownprefect
sphinx
|
|
| Lint rule | Added | Removed | Changed |
|---|---|---|---|
invalid-type-form |
0 | 2 | 0 |
| Total | 0 | 2 | 0 |
Flaky changes detected. This PR summary excludes flaky changes; see the HTML report for details.
Raw diff:
discord.py (https://github.com/Rapptz/discord.py)
- discord/ui/action_row.py:122:36 error[invalid-type-form] `ClassVar` cannot contain type variables
- discord/ui/container.py:109:35 error[invalid-type-form] `ClassVar` cannot contain type variables
charliermarsh
force-pushed
the
charlie/codex-classvar-typevars
branch
from
October 6, 2026 15:08
f8aba03 to
152f881
Compare
charliermarsh
force-pushed
the
charlie/codex-classvar-typevars
branch
3 times, most recently
from
October 6, 2026 16:53
7bc0e4a to
c1eaaf1
Compare
charliermarsh
force-pushed
the
charlie/codex-classvar-typevars
branch
from
October 6, 2026 18:00
ac5d888 to
b5875ea
Compare
charliermarsh
force-pushed
the
charlie/codex-classvar-typevars
branch
from
October 6, 2026 18:36
b5875ea to
bfa4db6
Compare
Reject instance arguments even when their members or type arguments contain TypeVarTuple objects. Avoid searching those members, which can recurse through changing specializations. Co-authored-by: Ibraheem Ahmed <ibraheem@ibraheem.ca>
Co-authored-by: Ibraheem Ahmed <ibraheem@ibraheem.ca>
Inspect dependencies on the setter signature explicitly, including recursive aliases, protocols, and TypedDicts. Recursive specializations that are independent of the setter parameters retain their writable-member checks. Co-authored-by: Ibraheem Ahmed <ibraheem@ibraheem.ca>
charliermarsh
force-pushed
the
charlie/codex-classvar-typevars
branch
from
October 6, 2026 20:03
bfa4db6 to
de8a824
Compare
charliermarsh
had a problem deploying
to
automations
October 6, 2026 20:04 — with
GitHub Actions
Failure
charliermarsh
removed this pull request from stack #29134
October 6, 2026 20:05
charliermarsh
added this pull request to stack #29150
October 6, 2026 20:05
Co-authored-by: Ibraheem Ahmed <ibraheem@ibraheem.ca>
charliermarsh
force-pushed
the
charlie/codex-classvar-typevars
branch
from
October 6, 2026 23:27
de8a824 to
aea36f4
Compare
Co-authored-by: Ibraheem Ahmed <ibraheem@ibraheem.ca>
Co-authored-by: Ibraheem Ahmed <ibraheem@ibraheem.ca>
charliermarsh
force-pushed
the
charlie/codex-classvar-typevars
branch
from
October 6, 2026 23:47
aea36f4 to
2b68aa1
Compare
charliermarsh
removed this pull request from stack #29150
October 6, 2026 23:50
charliermarsh
changed the base branch from
charlie/lazy-type-traversal
to
charlie/codex-explicit-type-visitors
October 6, 2026 23:50
charliermarsh
added this pull request to stack #29156
October 6, 2026 23:50
charliermarsh
force-pushed
the
charlie/codex-classvar-typevars
branch
from
October 7, 2026 01:00
2b68aa1 to
b8fdf4a
Compare
This branch was successfully deployed
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.
Summary
We now reject
ClassVarannotations whose types contain free type variables hidden by aliases or captured in protocol members andTypedDictfields. We also allowSelfin generic classes and type variables bound by a nested callable's own signature.The traversal expands alias values so unused arguments and arguments erased by specialization do not cause errors. It tracks callable bindings and treats type-variable bounds and defaults as metadata.
We follow finite recursive specializations, including cases where a protocol member or
TypedDictfield exposes a variable only after the first specialization. The shared recursion analysis distinguishes fixed outer variables from captures whose binding definitions also participate in the recursion. Occurrences beyond growing or unresolved recursive references can still remain undiagnosed; an incomplete search does not produce an error.We reuse completed searches under the same callable bindings to avoid repeatedly traversing shared types, such as those in Pydantic's
CoreSchema. An incomplete recursive search cannot supply a cached result.Builds on #29155.