Thanks to visit codestin.com
Credit goes to github.com

Skip to content

[ty] Suppress discarded TypedDict diagnostics#26250

Merged
charliermarsh merged 2 commits into
mainfrom
charlie/codex-suppress-discarded-typed-dict-diagnostics
Jun 23, 2026
Merged

[ty] Suppress discarded TypedDict diagnostics#26250
charliermarsh merged 2 commits into
mainfrom
charlie/codex-suppress-discarded-typed-dict-diagnostics

Conversation

@charliermarsh

@charliermarsh charliermarsh commented Jun 22, 2026

Copy link
Copy Markdown
Member

Summary

When we infer a dictionary literal against a union containing multiple TypedDict types, 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 TypedDict annotations and single-TypedDict unions 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::pydantic samples, 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.

@astral-sh-bot astral-sh-bot Bot added the ty Multi-file analysis & type inference label Jun 22, 2026
@astral-sh-bot

astral-sh-bot Bot commented Jun 22, 2026

Copy link
Copy Markdown

Typing conformance results

No changes detected ✅

Current numbers
The 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.

@astral-sh-bot

astral-sh-bot Bot commented Jun 22, 2026

Copy link
Copy Markdown

Memory usage report

Memory usage unchanged ✅

@astral-sh-bot

astral-sh-bot Bot commented Jun 22, 2026

Copy link
Copy Markdown

ecosystem-analyzer results

No diagnostic changes detected ✅

Full report with detailed diff (timing results)

@codspeed-hq

codspeed-hq Bot commented Jun 22, 2026

Copy link
Copy Markdown

Merging this PR will improve performance by 9.73%

⚡ 1 improved benchmark
✅ 70 untouched benchmarks
⏩ 64 skipped benchmarks1

Performance Changes

Mode Benchmark BASE HEAD Efficiency
WallTime pydantic 9.5 s 8.7 s +9.73%

Tip

Curious why this is faster? Use the CodSpeed MCP and ask your agent.


Comparing charlie/codex-suppress-discarded-typed-dict-diagnostics (16320f7) with main (06cb4ee)

Open in CodSpeed

Footnotes

  1. 64 benchmarks were skipped, so the baseline results were used instead. If they were deleted from the codebase, click here and archive them to remove them from the performance reports.

@charliermarsh charliermarsh force-pushed the charlie/codex-suppress-discarded-typed-dict-diagnostics branch 2 times, most recently from d4f3c21 to 74f875b Compare June 22, 2026 22:34
@charliermarsh charliermarsh force-pushed the charlie/codex-suppress-discarded-typed-dict-diagnostics branch from 74f875b to 0b7d667 Compare June 22, 2026 22:37
@charliermarsh charliermarsh marked this pull request as ready for review June 22, 2026 23:30
@charliermarsh charliermarsh requested a review from a team as a code owner June 22, 2026 23:30
@charliermarsh charliermarsh added the performance Potential performance improvement label Jun 22, 2026
@astral-sh-bot astral-sh-bot Bot requested a review from dcreager June 22, 2026 23:30
Comment thread crates/ty_python_semantic/src/types/infer/builder.rs Outdated
Comment thread crates/ty_python_semantic/src/types/context.rs
Comment thread crates/ty_python_semantic/src/types/context.rs Outdated
@charliermarsh

Copy link
Copy Markdown
Member Author

Thanks @ibraheemdev, fixed...

@charliermarsh charliermarsh merged commit 085c5cf into main Jun 23, 2026
61 checks passed
@charliermarsh charliermarsh deleted the charlie/codex-suppress-discarded-typed-dict-diagnostics branch June 23, 2026 00:53
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.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

performance Potential performance improvement ty Multi-file analysis & type inference

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants