[ty] Improve TypedDict -> dict assignment error diagnostics by sharkdp · Pull Request #24768 · astral-sh/ruff (original) (raw)
Summary
Improve the error message(s) that we show for a failing TypedDict to dict assignment.
closes astral-sh/ty#1646
Test Plan
Updated snapshot
Multi-file analysis & type inference
label
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.
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.
Memory usage report
Memory usage unchanged ✅
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 deleted the david/improve-td-dict branch
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 }})
