Skip to content

Fix TypedDict assignability: report required-mismatch for read-only target keys - #11860

Closed
Akhil Gupta (akhil9tiet) wants to merge 3 commits into
microsoft:mainfrom
akhil9tiet:fix/11859-typeddict-readonly-required
Closed

Akhil Gupta (akhil9tiet) wants to merge 3 commits into
microsoft:mainfrom
akhil9tiet:fix/11859-typeddict-readonly-required

Conversation

@akhil9tiet

Copy link
Copy Markdown

Fixes #11859

When a target TypedDict key is both required and read-only, pyright skipped the required/non-required assignability check entirely. Per the typing spec, read-only only relaxes the item-type rule (subtype instead of equivalent), not the required/non-required rule — so a NotRequired source key assigned to a required read-only target key must still error. The condition now reports the mismatch whenever the destination key is required, whether or not it is read-only.

@heejaechang

Copy link
Copy Markdown
Collaborator

🟢 Pyright CLI QA — ab83049a — verdict: green

Automated CLI checks compared this change with its base revision.
10 focused check(s) completed.

No new behavior difference was detected.

@rchiodo

Copy link
Copy Markdown
Collaborator

These requiredness checks are logically equivalent to the TypedDict fix in #11852, so I'm closing this in favor of that earlier PR, which also includes a regression sample. Thanks for digging into it.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

TypedDict assignability: NotRequired source key accepted for a Required ReadOnly target key

3 participants