Skip to content

[ty] Ban type qualifiers in PEP-695 type aliases#24242

Merged
AlexWaygood merged 1 commit intomainfrom
alex/695-qualifiers
Mar 27, 2026
Merged

[ty] Ban type qualifiers in PEP-695 type aliases#24242
AlexWaygood merged 1 commit intomainfrom
alex/695-qualifiers

Conversation

@AlexWaygood
Copy link
Copy Markdown
Member

We already ban these in PEP-613 aliases. Fixes astral-sh/ty#3150; closes #24224

@AlexWaygood AlexWaygood added the ty Multi-file analysis & type inference label Mar 27, 2026
@AlexWaygood AlexWaygood force-pushed the alex/695-qualifiers branch from 12c8390 to 57791cb Compare March 27, 2026 13:04
@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.59%. The percentage of expected errors that received a diagnostic held steady at 80.96%. The number of fully passing files held steady at 68/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 859 859 +0
False Positives 133 133 +0
False Negatives 202 202 +0
Total Diagnostics 1051 1051 +0
Precision 86.59% 86.59% +0.00%
Recall 80.96% 80.96% +0.00%
Passing Files 68/132 68/132 +0

True positives changed (1)

1 diagnostic
Test case Diff

aliases_type_statement.py:49

-error[fstring-type-annotation] Type expressions cannot use f-strings
+error[invalid-type-form] F-strings are not allowed in type expressions

@AlexWaygood AlexWaygood force-pushed the alex/695-qualifiers branch from 57791cb to 5653e13 Compare March 27, 2026 13:06
@AlexWaygood AlexWaygood changed the title alex/695 qualifiers [ty] Ban type qualifiers in PEP-695 type aliases Mar 27, 2026
@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)

Comment on lines +687 to +697
Some(KnownClass::InitVar) => {
if let Some(builder) = self.context.report_lint(&INVALID_TYPE_FORM, subscript) {
let diagnostic = builder.into_diagnostic(
"Type qualifier `dataclasses.InitVar` is not allowed in type \
expressions (only in annotation expressions)",
);
add_type_expression_reference_link(diagnostic);
}
self.infer_expression(slice, TypeContext::default());
Type::unknown()
}
Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

the special casing for InitVar in multiple places is a bit unfortunate -- I have an idea for resolving that, but will do it in a followup

@AlexWaygood AlexWaygood merged commit a943836 into main Mar 27, 2026
49 checks passed
@AlexWaygood AlexWaygood deleted the alex/695-qualifiers branch March 27, 2026 14:42
carljm added a commit that referenced this pull request Mar 31, 2026
* main: (40 commits)
  [ty] resolve union-likes in emitting union attribute errors (#24263)
  [ty] Improve support for `Callable` type context (#23888)
  [ty] Propagate type context through `await` expressions (#24256)
  [`pyflakes`] Flag annotated variable redeclarations as `F811` in preview mode (#24244)
  [ty] Preserve `Divergent` when materializing recursive aliases (#24245)
  Fix W391 fixes for consecutive empty notebook cells (#24236)
  [flake8-bugbear] Clarify RUF071 fix safety for non-path string comparisons (#24149)
  [ty] Ban type qualifiers in PEP-695 type aliases (#24242)
  [ty] Include keyword-prefixed symbols in completions for attributes (#24232)
  [ty] Add tests for TypedDict method overloads on unions (#24230)
  [ty] report unused bindings as unnecessary hint diagnostics (#23305)
  Remove unused `non_root` variable (#24238)
  Extend F507 to flag %-format strings with zero placeholders (#24215)
  [`flake8-simplify`] Suppress `SIM105` for `except*` before Python 3.12 (#23869)
  Ignore pre-initialization references in SIM113 (#24235)
  Parenthesize expression in RUF050 fix (#24234)
  Publish playgrounds using the `release-playground` environment (#24223)
  [ty] Fix instance-attribute lookup in methods of protocol classes (#24213)
  [ty] Used shared expression cache during generic call inference (#24219)
  [ty] make `Type::BoundMethod` include instances of same-named methods bound to a subclass (#24039)
  ...
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.

Missing error for Final in top level of type alias statement

4 participants