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

Skip to content

[ty] Prove TypedDict structural patterns exhaustive#26285

Merged
charliermarsh merged 6 commits into
mainfrom
charlie/typed-dict-pattern-exhaustiveness
Jun 25, 2026
Merged

[ty] Prove TypedDict structural patterns exhaustive#26285
charliermarsh merged 6 commits into
mainfrom
charlie/typed-dict-pattern-exhaustiveness

Conversation

@charliermarsh

Copy link
Copy Markdown
Member

Summary

This is the third and final stacked PR split from #26010. It is based on #26284.

Prior to this change, we retained only whether a mapping pattern was empty or nonempty. That is enough to recognize case {} as exhaustive for a mapping, but it cannot prove that a keyed pattern matches every value of a TypedDict. We also model TypedDict structurally rather than as a nominal dict subtype, even though every TypedDict value is a dictionary at runtime.

This retains each mapping key and nested pattern for subject-aware exhaustiveness. A keyed mapping pattern is exhaustive for a TypedDict only when every key is a string literal naming a required field and every nested pattern exhausts that field's declared type. Optional, absent, and non-string keys remain refutable.

The same runtime representation rule lets argumentless dict and Mapping class patterns, along with the positional dict match-self pattern, exhaust a TypedDict subject. Negative narrowing reuses the resulting definite-match type instead of treating every nonempty mapping pattern as opaque.

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

astral-sh-bot Bot commented Jun 23, 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.47%. The percentage of expected errors that received a diagnostic held steady at 89.19%. The number of fully passing files held steady at 95/134.

@astral-sh-bot

astral-sh-bot Bot commented Jun 23, 2026

Copy link
Copy Markdown

Memory usage report

Memory usage unchanged ✅

@astral-sh-bot

astral-sh-bot Bot commented Jun 23, 2026

Copy link
Copy Markdown

ecosystem-analyzer results

No diagnostic changes detected ✅

Full report with detailed diff (timing results)

@charliermarsh charliermarsh marked this pull request as ready for review June 24, 2026 00:06
@charliermarsh charliermarsh requested review from a team as code owners June 24, 2026 00:06
@charliermarsh charliermarsh force-pushed the charlie/positional-class-pattern-exhaustiveness branch from 8f587b7 to cc872c0 Compare June 24, 2026 00:09
@charliermarsh charliermarsh force-pushed the charlie/typed-dict-pattern-exhaustiveness branch from bb214c4 to d86cf11 Compare June 24, 2026 00:09
@charliermarsh charliermarsh force-pushed the charlie/positional-class-pattern-exhaustiveness branch from cc872c0 to 40451ee Compare June 24, 2026 00:35
@charliermarsh charliermarsh force-pushed the charlie/typed-dict-pattern-exhaustiveness branch from d86cf11 to acc9024 Compare June 24, 2026 00:36
@charliermarsh charliermarsh force-pushed the charlie/positional-class-pattern-exhaustiveness branch from 40451ee to e992ca4 Compare June 24, 2026 00:58
@charliermarsh charliermarsh force-pushed the charlie/typed-dict-pattern-exhaustiveness branch from acc9024 to e8cc088 Compare June 24, 2026 00:59
@codspeed-hq

codspeed-hq Bot commented Jun 24, 2026

Copy link
Copy Markdown

Merging this PR will not alter performance

✅ 73 untouched benchmarks
⏩ 64 skipped benchmarks1


Comparing charlie/typed-dict-pattern-exhaustiveness (3e9d92e) with main (6a0d2ec)

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/positional-class-pattern-exhaustiveness branch from e992ca4 to d3b1672 Compare June 24, 2026 01:34
@charliermarsh charliermarsh force-pushed the charlie/typed-dict-pattern-exhaustiveness branch from e8cc088 to 2316ebb Compare June 24, 2026 01:34
@charliermarsh charliermarsh force-pushed the charlie/positional-class-pattern-exhaustiveness branch from d3b1672 to 724661e Compare June 24, 2026 11:31
@charliermarsh charliermarsh force-pushed the charlie/typed-dict-pattern-exhaustiveness branch from 2316ebb to cfbac08 Compare June 24, 2026 11:31
@charliermarsh charliermarsh force-pushed the charlie/positional-class-pattern-exhaustiveness branch from 724661e to dc19cb4 Compare June 25, 2026 11:30
Base automatically changed from charlie/positional-class-pattern-exhaustiveness to main June 25, 2026 11:35
@charliermarsh charliermarsh force-pushed the charlie/typed-dict-pattern-exhaustiveness branch from cfbac08 to feed4cb Compare June 25, 2026 11:42
@charliermarsh charliermarsh merged commit e700ea3 into main Jun 25, 2026
63 checks passed
@charliermarsh charliermarsh deleted the charlie/typed-dict-pattern-exhaustiveness branch June 25, 2026 14:06
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

ty Multi-file analysis & type inference

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants