[ty] Default-specialization of generic type aliases#21765
Merged
Conversation
Diagnostic diff on typing conformance testsChanges were detected when running ty on typing conformance tests--- old-output.txt 2025-12-02 20:50:07.128924253 +0000
+++ new-output.txt 2025-12-02 20:50:10.790957699 +0000
@@ -470,7 +470,6 @@
generics_defaults_referential.py:37:10: error[invalid-argument-type] Argument to bound method `__init__` is incorrect: Expected `int`, found `Literal[""]`
generics_defaults_referential.py:94:1: error[type-assertion-failure] Type `type[Bar[Any, list[Any]]]` does not match asserted type `<class 'Bar'>`
generics_defaults_referential.py:95:1: error[type-assertion-failure] Type `type[Bar[int, list[int]]]` does not match asserted type `<class 'Bar[int, list[int]]'>`
-generics_defaults_specialization.py:26:5: error[type-assertion-failure] Type `SomethingWithNoDefaults[int, str]` does not match asserted type `SomethingWithNoDefaults[int, DefaultStrT]`
generics_defaults_specialization.py:30:15: error[invalid-type-arguments] Too many type arguments: expected between 0 and 1, got 2
generics_defaults_specialization.py:45:1: error[type-assertion-failure] Type `type[Bar[str]]` does not match asserted type `<class 'Bar'>`
generics_paramspec_basic.py:10:1: error[invalid-paramspec] The name of a `ParamSpec` (`NotIt`) must match the name of the variable it is assigned to (`WrongName`)
@@ -1029,4 +1028,4 @@
typeddicts_usage.py:28:17: error[missing-typed-dict-key] Missing required key 'name' in TypedDict `Movie` constructor
typeddicts_usage.py:28:18: error[invalid-key] Unknown key "title" for TypedDict `Movie`: Unknown key "title"
typeddicts_usage.py:40:24: error[invalid-type-form] The special form `typing.TypedDict` is not allowed in type expressions
-Found 1031 diagnostics
+Found 1030 diagnostics
|
|
|
| Lint rule | Added | Removed | Changed |
|---|---|---|---|
no-matching-overload |
3 | 453 | 0 |
type-assertion-failure |
24 | 171 | 184 |
unsupported-operator |
1 | 283 | 1 |
invalid-argument-type |
5 | 239 | 26 |
invalid-return-type |
0 | 206 | 3 |
invalid-parameter-default |
0 | 134 | 3 |
invalid-assignment |
0 | 52 | 3 |
invalid-context-manager |
0 | 0 | 32 |
unresolved-attribute |
9 | 14 | 2 |
invalid-type-form |
0 | 9 | 8 |
non-subscriptable |
2 | 15 | 0 |
unused-ignore-comment |
8 | 0 | 0 |
not-iterable |
1 | 3 | 1 |
possibly-missing-attribute |
1 | 2 | 0 |
unsupported-base |
2 | 0 | 0 |
call-non-callable |
0 | 1 | 0 |
invalid-method-override |
0 | 1 | 0 |
| Total | 56 | 1,583 | 263 |
CodSpeed Performance ReportMerging #21765 will degrade performances by 5.37%Comparing Summary
Benchmarks breakdown
Footnotes
|
fa8f088 to
c6a2501
Compare
This was referenced Dec 3, 2025
dcreager
added a commit
that referenced
this pull request
Dec 3, 2025
* origin/main: [ty] Improve `@override`, `@final` and Liskov checks in cases where there are multiple reachable definitions (#21767) [ty] Extend `invalid-explicit-override` to also cover properties decorated with `@override` that do not override anything (#21756) [ty] Enable LRU collection for parsed module (#21749) [ty] Support typevar-specialized dynamic types in generic type aliases (#21730) Add token based `parenthesized_ranges` implementation (#21738) [ty] Default-specialization of generic type aliases (#21765) [ty] Suppress false positives when `dataclasses.dataclass(...)(cls)` is called imperatively (#21729) [syntax-error] Default type parameter followed by non-default type parameter (#21657) new module for parsing ranged suppressions (#21441) [ty] `type[T]` is assignable to an inferable typevar (#21766) Fix syntax error false positives for `await` outside functions (#21763) [ty] Improve diagnostics for unsupported comparison operations (#21737) Move `Token`, `TokenKind` and `Tokens` to `ruff-python-ast` (#21760) [ty] Don't confuse multiple occurrences of `typing.Self` when binding bound methods (#21754) Use our org-wide Renovate preset (#21759) Delete `my-script.py` (#21751) [ty] Move `all_members`, and related types/routines, out of `ide_support.rs` (#21695)
dcreager
added a commit
that referenced
this pull request
Dec 3, 2025
* origin/main: [ty] Reachability constraints: minor documentation fixes (#21774) [ty] Fix non-determinism in `ConstraintSet.specialize_constrained` (#21744) [ty] Improve `@override`, `@final` and Liskov checks in cases where there are multiple reachable definitions (#21767) [ty] Extend `invalid-explicit-override` to also cover properties decorated with `@override` that do not override anything (#21756) [ty] Enable LRU collection for parsed module (#21749) [ty] Support typevar-specialized dynamic types in generic type aliases (#21730) Add token based `parenthesized_ranges` implementation (#21738) [ty] Default-specialization of generic type aliases (#21765) [ty] Suppress false positives when `dataclasses.dataclass(...)(cls)` is called imperatively (#21729) [syntax-error] Default type parameter followed by non-default type parameter (#21657)
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
Implement default-specialization of generic type aliases (implicit or PEP-613) if they are used in a type expression without an explicit specialization.
closes astral-sh/ty#1690
Typing conformance
-generics_defaults_specialization.py:26:5: error[type-assertion-failure] Type `SomethingWithNoDefaults[int, str]` does not match asserted type `SomethingWithNoDefaults[int, DefaultStrT]`That's exactly what we want ✔️
All other tests in this file pass as well, with the exception of this assertion, which is just wrong (at least according to our interpretation,
type[Bar] != <class 'Bar'>). I checked that we do correctly default-specialize the type parameter which is not displayed in the diagnostic that we raise.Ecosystem impact
Looks like I should have included this last week 😎
Test Plan
Updated pre-existing tests and add a few new ones.