[ty] Prefer declared type for invariant collection literals#20927
Merged
ibraheemdev merged 2 commits intomainfrom Oct 16, 2025
Merged
[ty] Prefer declared type for invariant collection literals#20927ibraheemdev merged 2 commits intomainfrom
ibraheemdev merged 2 commits intomainfrom
Conversation
Contributor
Diagnostic diff on typing conformance testsNo changes detected when running ty on typing conformance tests ✅ |
Contributor
|
Contributor
|
| Lint rule | Added | Removed | Changed |
|---|---|---|---|
invalid-argument-type |
6 | 276 | 7 |
possibly-missing-implicit-call |
0 | 56 | 1 |
possibly-missing-attribute |
1 | 38 | 0 |
unsupported-operator |
1 | 31 | 3 |
invalid-assignment |
0 | 24 | 3 |
unresolved-attribute |
15 | 0 | 0 |
non-subscriptable |
0 | 14 | 0 |
unused-ignore-comment |
6 | 1 | 0 |
invalid-return-type |
0 | 1 | 5 |
no-matching-overload |
0 | 6 | 0 |
index-out-of-bounds |
0 | 2 | 0 |
not-iterable |
0 | 2 | 0 |
invalid-await |
0 | 0 | 1 |
redundant-cast |
1 | 0 | 0 |
type-assertion-failure |
0 | 1 | 0 |
| Total | 30 | 452 | 20 |
Member
|
(Retitled the PR because tuples are also collection literals, but those don't look like they're touched by this PR -- a decision which I support!) |
AlexWaygood
approved these changes
Oct 16, 2025
b763bb9 to
ed53e9b
Compare
CodSpeed Performance ReportMerging #20927 will improve performances by 5.14%Comparing Summary
Benchmarks breakdown
Footnotes
|
Member
Author
|
Looks like there are no regressions in the ecosystem report and a lot of clear improvements, so hopefully this is fairly uncontroversial (I also discussed this with @carljm and he agreed). |
dcreager
added a commit
that referenced
this pull request
Oct 17, 2025
* main: [ty] Prefer declared type for invariant collection literals (#20927) [ty] Don't track inferability via different `Type` variants (#20677) [ty] Use declared variable types as bidirectional type context (#20796) [ty] Avoid unnecessarily widening generic specializations (#20875) [ty] Support dataclass-transform `field_specifiers` (#20888) Bump 0.14.1 (#20925) Standardize syntax error construction (#20903) [`pydoclint`] Implement `docstring-extraneous-parameter` (`DOC102`) (#20376) [ty] Fix panic 'missing root' when handling completion request (#20917) [ty] Run file watching tests serial when using nextest (#20918) [ty] Add version hint for failed stdlib attribute accesses (#20909) More CI improvements (#20920) [ty] Check typeshed VERSIONS for parent modules when reporting failed stdlib imports (#20908)
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
Prefer the declared type for collection literals, e.g.,
This solves a large part of astral-sh/ty#136 for invariant generics, where respecting the declared type is a lot more important. It also means that annotated dict literals with
dict[_, Any]is a way out of astral-sh/ty#1248.