Skip to content

[ty] Validate type qualifiers in functional TypedDict fields and the extra_items keyword to functional TypedDicts - #24360

Merged
AlexWaygood merged 1 commit into
mainfrom
alex/functional-td-qualifiers
Apr 2, 2026
Merged

AlexWaygood merged 1 commit into
mainfrom
alex/functional-td-qualifiers

Conversation

@AlexWaygood

Copy link
Copy Markdown
Member

Summary

Emit a diagnostic on nonsensical types such as these:

from typing import TypedDict, ClassVar, Final

TD1 = TypedDict("TD1", {"x": ClassVar[int]})
TD2 = TypedDict("TD2", {}, extra_items=Final[str])

Test Plan

mdtests

@AlexWaygood
AlexWaygood requested a review from carljm as a code owner April 2, 2026 10:43
@AlexWaygood AlexWaygood added the ty The ty type checker label Apr 2, 2026
@astral-sh-bot

astral-sh-bot Bot commented Apr 2, 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 86.76%. The percentage of expected errors that received a diagnostic held steady at 81.53%. The number of fully passing files held steady at 70/132.

@astral-sh-bot

astral-sh-bot Bot commented Apr 2, 2026 •

Copy link
Copy Markdown

Memory usage report

Memory usage unchanged ✅

@astral-sh-bot

astral-sh-bot Bot commented Apr 2, 2026 •

Copy link
Copy Markdown

ecosystem-analyzer results

Lint rule Added Removed Changed
invalid-await 0 40 0
invalid-return-type 0 1 0
Total 0 41 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)

@charliermarsh

Copy link
Copy Markdown
Member

Dumb question: at least on main, it seems like we allow these for class-based TypedDict. Why is it different for functional?

@charliermarsh

Copy link
Copy Markdown
Member

Oh, hah, ok I see that we validate extra_items for class-based in #24362. But why is TypedDict("TD1", {"x": ClassVar[int]}) forbidden?

@AlexWaygood

AlexWaygood commented Apr 2, 2026 •

Copy link
Copy Markdown
Member Author

But why is TypedDict("TD1", {"x": ClassVar[int]}) forbidden?

It doesn't mean anything; ClassVar is just going to be ignored by ty there. The same thing for class-based TypedDicts is also validated by another PR in this stack ;) but one beneath this PR instead of one above it

@charliermarsh

Copy link
Copy Markdown
Member

Alas, I looked for that PR but couldn't find it on the front page, turns out it's on the, uh, second page! Okay thank you.

@AlexWaygood
AlexWaygood force-pushed the alex/refactor-qualifiers branch from e4a6f0e to 17c5acf Compare April 2, 2026 16:13
@AlexWaygood
AlexWaygood requested a review from MichaReiser as a code owner April 2, 2026 16:13
Base automatically changed from alex/refactor-qualifiers to main April 2, 2026 16:19
…`extra_items` functional TypedDict keyword argument
@AlexWaygood
AlexWaygood force-pushed the alex/functional-td-qualifiers branch from f3fc283 to c8adbca Compare April 2, 2026 16:20
@AlexWaygood
AlexWaygood enabled auto-merge (squash) April 2, 2026 16:21
@AlexWaygood
AlexWaygood merged commit a617c54 into main Apr 2, 2026
51 checks passed
@AlexWaygood
AlexWaygood deleted the alex/functional-td-qualifiers branch April 2, 2026 16:26
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 The ty type checker

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants