Skip to content

Fix TypedDict with extra_items type - #1000

Merged
mauvilsa merged 2 commits into
mainfrom
fix-typed-dict-extra-items
Oct 2, 2026
Merged

mauvilsa merged 2 commits into
mainfrom
fix-typed-dict-extra-items

Conversation

@mauvilsa

@mauvilsa mauvilsa commented Oct 2, 2026 •

Copy link
Copy Markdown
Owner

What does this PR do?

Fixes TypedDict with extra_items (PEP 728) rejecting keys it doesn't declare with Unexpected keys. Those keys are now accepted and validated against the extra_items type, including when extra_items is inherited from a base TypedDict (unless the subclass is closed). Undeclared keys are still rejected when there is no extra_items.

Before submitting

  • Did you read the contributing guideline?
  • If you used a coding agent, did you fully understand and validate all generated code and ensure it follows the contributing guidelines?
  • Did you update the documentation? (readme and public docstrings)
  • Did you write unit tests such that there is 100% coverage on related code? (required for bug fixes and new features)
  • Did you verify that new and existing tests pass locally?
  • If this is a bug fix, did you verify that the tests fail without the code fix?
  • Did you make sure that all changes preserve backward compatibility?
  • Did you update the CHANGELOG including a pull request link? (not for typos, docs, test updates, or minor internal changes/refactors)

@mauvilsa mauvilsa added the bug Something isn't working label Oct 2, 2026
@mauvilsa
mauvilsa deployed to sonarcloud October 2, 2026 16:37 — with GitHub Actions Active
@greptile-apps

greptile-apps Bot commented Oct 2, 2026 •

Copy link
Copy Markdown

RetriggerConfidence Score: 4/5

[Medium risk] Adds support for TypedDict extra_items validation.

The PR should not merge until generic TypedDict extra values are validated against their substituted type.

Findings

  1. P1 Generic extra values go unvalidated ▶
  2. P2 Schema rejects valid extra keys ▶

Summary

The PR adds PEP 728 TypedDict extra_items support when parsing, with documentation and tests for basic values, inheritance, and closed TypedDicts.

  • Generic extra-item types do not receive the TypeVar substitution applied to declared keys.
  • Generated JSON Schema still rejects extra keys that parsing now accepts.

Reviews (1) · Last reviewed commit: "Fix TypedDict with etra_items type"

Comment thread jsonargparse/_typehints.py Outdated
Comment thread jsonargparse/_typehints.py
@codecov

codecov Bot commented Oct 2, 2026 •

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 100.00%. Comparing base (d2350da) to head (62904ef).
⚠️ Report is 1 commits behind head on main.
✅ All tests successful. No failed tests found.

Additional details and impacted files
@@            Coverage Diff            @@
##              main     #1000   +/-   ##
=========================================
  Coverage   100.00%   100.00%           
=========================================
  Files           27        27           
  Lines         9657      9681   +24     
=========================================
+ Hits          9657      9681   +24     

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

@mauvilsa
mauvilsa deployed to sonarcloud October 2, 2026 19:35 — with GitHub Actions Active
@sonarqubecloud

sonarqubecloud Bot commented Oct 2, 2026

Copy link
Copy Markdown

@mauvilsa mauvilsa changed the title Fix TypedDict with etra_items type Fix TypedDict with extra_items type Oct 2, 2026
@mauvilsa
mauvilsa merged commit 5070670 into main Oct 2, 2026
32 checks passed
@mauvilsa
mauvilsa deleted the fix-typed-dict-extra-items branch October 2, 2026 19:43

This branch was successfully deployed

1 active deployment
sonarcloud — 62904ef3 Deployed Oct 2, 2026 by mauvilsa via sonarcloud #938
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug Something isn't working

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant