[ty] Improve TypedDict -> dict assignment error diagnostics by sharkdp · Pull Request #24768 · astral-sh/ruff (original) (raw)

@sharkdp

Summary

Improve the error message(s) that we show for a failing TypedDict to dict assignment.

image

closes astral-sh/ty#1646

Test Plan

Updated snapshot

@sharkdp sharkdp added the ty

Multi-file analysis & type inference

label

Apr 21, 2026

@sharkdp

@astral-sh-bot

Typing conformance results

No changes detected ✅

Current numbers
The percentage of diagnostics emitted that were expected errors held steady at 87.94%. The percentage of expected errors that received a diagnostic held steady at 83.36%. The number of fully passing files held steady at 79/133.

sharkdp

Comment on lines +413 to +415

for help_message in help_messages {
diag.help(help_message.to_string());
}

Choose a reason for hiding this comment

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

We render these help messages at the end in order to keep the error context tree concise in its messages. We also use a hash map for deduplication: if you assign a TypedDict to a union of multiple dict types, it's enough to show this hint once.

@astral-sh-bot

Memory usage report

Memory usage unchanged ✅

@astral-sh-bot

AlexWaygood

AlexWaygood

Choose a reason for hiding this comment

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

Love it

fn render(
&self,
db: &'db dyn Db,
help_messages: &mut FxOrderSet,

Choose a reason for hiding this comment

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

nit: this could probably be an FxIndexSet? (don't think it really matters though; FxOrderSet is just a wrapper over the top of FxIndexSet that adds Hash and Eq impls)

Choose a reason for hiding this comment

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

I like that FxOrderSet has "order" in its name, because that's what is important here.

@sharkdp

@sharkdp sharkdp deleted the david/improve-td-dict branch

April 21, 2026 15:26

This was referenced

Apr 27, 2026

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

[ Show hidden characters]({{ revealButtonHref }})