Skip to content

[ty] Improve robustness of various type-qualifier-related checks#24251

Merged
AlexWaygood merged 1 commit intomainfrom
alex/refactor-qualifiers
Apr 2, 2026
Merged

[ty] Improve robustness of various type-qualifier-related checks#24251
AlexWaygood merged 1 commit intomainfrom
alex/refactor-qualifiers

Conversation

@AlexWaygood
Copy link
Copy Markdown
Member

@AlexWaygood AlexWaygood commented Mar 27, 2026

Summary

Some type qualifiers are only valid in certain contexts, even inside annotation expressions. For example, x: ClassVar[int] is only valid inside a class scope, and even then, it's only valid if the class is not a TypedDict. We already have checks to catch this kind of error, but the checks have some gaps. This PR fixes the gaps by using exhaustive matches over the TypeQualifier and CodeGeneratorKind enums.

Test Plan

Pre-existing TODOs in mdtests are fixed, and new mdtests are added.

@AlexWaygood AlexWaygood added the ty Multi-file analysis & type inference label Mar 27, 2026
@astral-sh-bot
Copy link
Copy Markdown

astral-sh-bot bot commented Mar 27, 2026

Typing conformance results

The percentage of diagnostics emitted that were expected errors held steady at 86.76%. The percentage of expected errors that received a diagnostic held steady at 81.53%. The number of fully passing files held steady at 70/132.

Summary

How are test cases classified?

Each test case represents one expected error annotation or a group of annotations sharing a tag. Counts are per test case, not per diagnostic — multiple diagnostics on the same line count as one. Required annotations (E) are true positives when ty flags the expected location and false negatives when it does not. Optional annotations (E?) are true positives when flagged but true negatives (not false negatives) when not. Tagged annotations (E[tag]) require ty to flag exactly one of the tagged lines; tagged multi-annotations (E[tag+]) allow any number up to the tag count. Flagging unexpected locations counts as a false positive.

Metric Old New Diff Outcome
True Positives 865 865 +0
False Positives 132 132 +0
False Negatives 196 196 +0
Total Diagnostics 1050 1050 +0
Precision 86.76% 86.76% +0.00%
Recall 81.53% 81.53% +0.00%
Passing Files 70/132 70/132 +0

True positives changed (2)

2 diagnostics
Test case Diff

classes_classvar.py:70

-error[invalid-type-form] `ClassVar` annotations are only allowed in class-body scopes
+error[invalid-type-form] `ClassVar` is only allowed in class bodies

classes_classvar.py:77

-error[invalid-type-form] `ClassVar` annotations are only allowed in class-body scopes
+error[invalid-type-form] `ClassVar` is only allowed in class bodies

@astral-sh-bot
Copy link
Copy Markdown

astral-sh-bot bot commented Mar 27, 2026

Memory usage report

Memory usage unchanged ✅

@astral-sh-bot
Copy link
Copy Markdown

astral-sh-bot bot commented Mar 27, 2026

ecosystem-analyzer results

No diagnostic changes detected ✅

Full report with detailed diff (timing results)

@AlexWaygood AlexWaygood force-pushed the alex/initvar-special branch from 0df65a0 to 825d237 Compare March 30, 2026 10:16
Base automatically changed from alex/initvar-special to main March 30, 2026 10:20
@AlexWaygood AlexWaygood force-pushed the alex/refactor-qualifiers branch 4 times, most recently from e0b6be4 to e4a6f0e Compare April 1, 2026 21:20
@AlexWaygood AlexWaygood changed the base branch from main to alex/return-param-type-expr April 1, 2026 21:21
@AlexWaygood AlexWaygood closed this Apr 1, 2026
@AlexWaygood AlexWaygood reopened this Apr 1, 2026
@AlexWaygood AlexWaygood marked this pull request as ready for review April 1, 2026 21:31
@AlexWaygood AlexWaygood force-pushed the alex/return-param-type-expr branch from 4dd20b4 to 82efcdd Compare April 2, 2026 15:13
@AlexWaygood AlexWaygood requested a review from MichaReiser as a code owner April 2, 2026 15:13
@AlexWaygood AlexWaygood force-pushed the alex/return-param-type-expr branch from 82efcdd to 0bf4a84 Compare April 2, 2026 15:21
Base automatically changed from alex/return-param-type-expr to main April 2, 2026 16:05
@AlexWaygood AlexWaygood force-pushed the alex/refactor-qualifiers branch from e4a6f0e to 17c5acf Compare April 2, 2026 16:13
@AlexWaygood AlexWaygood merged commit d851708 into main Apr 2, 2026
50 of 51 checks passed
@AlexWaygood AlexWaygood deleted the alex/refactor-qualifiers branch April 2, 2026 16:19
carljm added a commit that referenced this pull request Apr 2, 2026
* main:
  [ty] Improve robustness of various type-qualifier-related checks (#24251)
  Only run the release-gate on workflow dispatch (#24366)
  [ty] Use `infer_type_expression` for parsing parameter annotations and return-type annotations (#24353)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

ty Multi-file analysis & type inference

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants