Skip to content

[ty] Infer the extra_items keyword argument to class-based TypedDicts as an annotation expression#24362

Merged
AlexWaygood merged 1 commit intomainfrom
alex/class-td-extra-items
Apr 2, 2026
Merged

[ty] Infer the extra_items keyword argument to class-based TypedDicts as an annotation expression#24362
AlexWaygood merged 1 commit intomainfrom
alex/class-td-extra-items

Conversation

@AlexWaygood
Copy link
Copy Markdown
Member

Summary

Reject illegal TypedDict classes such as class TD(TypedDict, extra_items=42), and validate qualifiers passed to extra_items.

Test Plan

mdtests updated and extended

@AlexWaygood AlexWaygood added the ty Multi-file analysis & type inference label Apr 2, 2026
@astral-sh-bot
Copy link
Copy Markdown

astral-sh-bot bot commented Apr 2, 2026

Typing conformance results improved 🎉

The percentage of diagnostics emitted that were expected errors increased from 86.76% to 86.79%. The percentage of expected errors that received a diagnostic increased from 81.53% to 81.72%. The number of fully passing files held steady at 70/132.

Summary

How are test cases classified?

Each test case represents one expected error annotation or a group of annotations sharing a tag. Counts are per test case, not per diagnostic — multiple diagnostics on the same line count as one. Required annotations (E) are true positives when ty flags the expected location and false negatives when it does not. Optional annotations (E?) are true positives when flagged but true negatives (not false negatives) when not. Tagged annotations (E[tag]) require ty to flag exactly one of the tagged lines; tagged multi-annotations (E[tag+]) allow any number up to the tag count. Flagging unexpected locations counts as a false positive.

Metric Old New Diff Outcome
True Positives 865 867 +2 ⏫ (✅)
False Positives 132 132 +0
False Negatives 196 194 -2 ⏬ (✅)
Total Diagnostics 1050 1052 +2
Precision 86.76% 86.79% +0.03% ⏫ (✅)
Recall 81.53% 81.72% +0.19% ⏫ (✅)
Passing Files 70/132 70/132 +0

Test file breakdown

1 file altered
File True Positives False Positives False Negatives Status
typeddicts_extra_items.py 11 (+2) ✅ 22 17 (-2) ✅ 📈 Improving
Total (all files) 867 (+2) ✅ 132 194 (-2) ✅ 70/132

True positives added (2)

2 diagnostics
Test case Diff

typeddicts_extra_items.py:114

+error[invalid-type-form] Type qualifier `typing.Required` is not valid in a TypedDict `extra_items` argument

typeddicts_extra_items.py:117

+error[invalid-type-form] Type qualifier `typing.NotRequired` is not valid in a TypedDict `extra_items` argument

@astral-sh-bot
Copy link
Copy Markdown

astral-sh-bot bot commented Apr 2, 2026

Memory usage report

Memory usage unchanged ✅

@astral-sh-bot
Copy link
Copy Markdown

astral-sh-bot bot commented Apr 2, 2026

ecosystem-analyzer results

Lint rule Added Removed Changed
invalid-await 40 0 0
invalid-return-type 1 0 0
Total 41 0 0

Changes in flaky projects detected. Raw diff output excludes flaky projects; see the HTML report for details.

Full report with detailed diff (timing results)

@AlexWaygood AlexWaygood force-pushed the alex/functional-td-qualifiers branch from f3fc283 to c8adbca Compare April 2, 2026 16:20
@AlexWaygood AlexWaygood requested a review from MichaReiser as a code owner April 2, 2026 16:20
Base automatically changed from alex/functional-td-qualifiers to main April 2, 2026 16:26
@AlexWaygood AlexWaygood force-pushed the alex/class-td-extra-items branch from 814e002 to a463cc7 Compare April 2, 2026 16:27
@AlexWaygood AlexWaygood enabled auto-merge (squash) April 2, 2026 16:27
@carljm carljm removed their request for review April 2, 2026 16:30
@AlexWaygood AlexWaygood merged commit 130da28 into main Apr 2, 2026
51 checks passed
@AlexWaygood AlexWaygood deleted the alex/class-td-extra-items branch April 2, 2026 16:31
carljm added a commit that referenced this pull request Apr 3, 2026
* main:
  Document adding fixes in CONTRIBUTING.md (#24393)
  Sort formatter diagnostics in snapshots (#24375)
  [`pyupgrade`] Fix panic caused by handling of octals in `UP012` (#24390)
  Upgrade to nix v0.31.2 (#24385)
  Strip form feeds from indent passed to `dedent_to` (#24381)
  add recent move of the `deferred` submodule to `.git-blame-ignore-revs` (#24379)
  [ty] Fix extra_items TypedDict tests (#24367)
  [ty] Use `infer_type_expression` for validating PEP-613 type aliases (#24370)
  [`flake8-simplify`] Make the fix for `collapsible-if` (`SIM102`) safe in `preview` (#24371)
  [ty] Validate TypedDict fields when subclassing (#24338)
  [ty] pass type context to sequence literals in binary operations (#24197)
  Add release environment to notify-dependents job (#24372)
  Bump 0.15.9 (#24369)
  [ty] Move the `deferred` submodule inside `infer/builder` (#24368)
  [ty] Infer the `extra_items` keyword argument to class-based TypedDicts as an annotation expression (#24362)
  [ty] Validate type qualifiers in functional TypedDict fields and the `extra_items` keyword to functional TypedDicts (#24360)
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.

3 participants