[ty] Suppress discarded TypedDict diagnostics#26250
Merged
charliermarsh merged 2 commits intoJun 23, 2026
Merged
Conversation
Typing conformance resultsNo changes detected ✅Current numbersThe percentage of diagnostics emitted that were expected errors held steady at 94.37%. The percentage of expected errors that received a diagnostic held steady at 89.00%. The number of fully passing files held steady at 94/134. |
Memory usage reportMemory usage unchanged ✅ |
|
Merging this PR will improve performance by 9.73%
Performance Changes
Tip Curious why this is faster? Use the CodSpeed MCP and ask your agent. Comparing Footnotes
|
d4f3c21 to
74f875b
Compare
74f875b to
0b7d667
Compare
ibraheemdev
reviewed
Jun 22, 2026
Member
Author
|
Thanks @ibraheemdev, fixed... |
ibraheemdev
approved these changes
Jun 23, 2026
charliermarsh
added a commit
that referenced
this pull request
Jun 23, 2026
## Summary `speculate()` creates a fresh inference builder whose diagnostics are discarded unless the caller later inspects or merges its context. Prior to this change, 20 speculative inference passes used only the inferred types, constraints, or applicability result, but still constructed and formatted diagnostics before dropping the builder. This reuses `speculate_without_diagnostics()` from #26250 at every call site that does not consume diagnostics. It covers call-argument multi-inference, `MultiInferenceGuard::infer_silent`, `TypeForm` and type-expression probes, and secondary `TypedDict`, dictionary, binary-expression, call, and subscript inference. The six speculative paths that inspect diagnostics or merge a successful builder continue to use `speculate()`. The change is intended to preserve inference and diagnostic behavior; it only avoids work whose result was already discarded. ## Performance This is intentionally a draft so CodSpeed can measure the aggregate effect across the benchmark suite.
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
When we infer a dictionary literal against a union containing multiple
TypedDicttypes, we speculatively validate the literal against each candidate. Prior to this change, rejected candidates still constructed and formatted diagnostics even though we discarded the candidate builder and its diagnostics.This adds scoped diagnostic suppression around candidate validation. Key and value inference, including nested speculation, continues with diagnostics enabled; only the final validation of already-inferred item types is suppressed. Direct
TypedDictannotations and single-TypedDictunions without a compatible fallback continue to report diagnostics normally.The regression coverage ensures that a mixed
TypedDict | dict[...]fallback remains quiet while nested inference can still use speculative diagnostics to select its fallback.Performance
Across 21 single-threaded
ty_walltime::pydanticsamples, median and p95 both improve by 9.7% (3.377s to 3.049s median; 3.394s to 3.064s p95). Matched Callgrind runs retire 12.35% fewer instructions; the discarded validation-diagnostic edge falls by 99.79%, while the control workload is unchanged.