Skip to content

[ty] Initial test suite for PEP-728 TypedDict features#23832

Merged
AlexWaygood merged 6 commits intomainfrom
alex-carl/pep-728
Mar 12, 2026
Merged

[ty] Initial test suite for PEP-728 TypedDict features#23832
AlexWaygood merged 6 commits intomainfrom
alex-carl/pep-728

Conversation

@AlexWaygood
Copy link
Copy Markdown
Member

Summary

This PR adds an initial test suite for closed=True and extra_items TypedDicts, both originally introduced by PEP 728. The spec for TypedDicts is here, and the conformance-suite tests for PEP 728 features are here.

Note that we already have some existing tests for the closed=True keyword here:

It is invalid to pass non-`bool`s to the `total` and `closed` keyword arguments:
```py
class Bar(TypedDict, total=42): ... # error: [invalid-argument-type]
class Baz(TypedDict, closed=None): ... # error: [invalid-argument-type]
```
And it's also invalid to pass an object of type `bool` -- according to the spec:
> The value must be exactly `True` or `False`; other expressions are not allowed.
```py
def f(is_total: bool):
class VeryDynamic(TypedDict, total=is_total): ... # error: [invalid-argument-type]
```

Test Plan

this pr is all tests

Co-authored-by: Carl Meyer [email protected]

AlexWaygood and others added 4 commits March 5, 2026 19:28
Replace the TODO comment about closed TypedDict narrowing with actual
test cases that assert current behavior and mark expected improvements
with TODO comments.

Co-Authored-By: Claude Opus 4.6 <[email protected]>
Update all PEP 728 (`closed` and `extra_items`) test assertions to
match current behavior since these features aren't fully implemented
yet. Each incorrect assertion is marked with a TODO comment describing
the expected behavior once support is complete.

Co-Authored-By: Claude Opus 4.6 <[email protected]>
@AlexWaygood AlexWaygood added testing Related to testing Ruff itself ty Multi-file analysis & type inference labels Mar 9, 2026
@AlexWaygood AlexWaygood marked this pull request as ready for review March 9, 2026 11:31
@AlexWaygood
Copy link
Copy Markdown
Member Author

I'd actually be most interested in @sharkdp's review on this one 😃

@AlexWaygood AlexWaygood assigned sharkdp and unassigned carljm Mar 9, 2026
@AlexWaygood
Copy link
Copy Markdown
Member Author

For transparency: the title of the first commit ee79262 is "Claude's initial pass on a test suite". @carljm and I went through the spec and the conformance suite fairly exhaustively and added the subheadings for the tests we would like to add, and then had Claude write the actual tests based on those subheadings. I then went through Claude's tests and reviewed them for correctness, making fixes in subsequent commits.

@carljm carljm removed their request for review March 9, 2026 23:45
Copy link
Copy Markdown
Contributor

@sharkdp sharkdp left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Cool — thank you very much for the exhaustive tests!

Comment thread crates/ty_python_semantic/resources/mdtest/typed_dict.md Outdated
Comment thread crates/ty_python_semantic/resources/mdtest/typed_dict.md Outdated
Comment thread crates/ty_python_semantic/resources/mdtest/typed_dict.md
Comment thread crates/ty_python_semantic/resources/mdtest/typed_dict.md Outdated
Comment thread crates/ty_python_semantic/resources/mdtest/typed_dict.md
Comment thread crates/ty_python_semantic/resources/mdtest/typed_dict.md Outdated
Comment thread crates/ty_python_semantic/resources/mdtest/typed_dict.md Outdated
Comment thread crates/ty_python_semantic/resources/mdtest/typed_dict.md
Comment thread crates/ty_python_semantic/resources/mdtest/typed_dict.md Outdated
Comment thread crates/ty_python_semantic/resources/mdtest/typed_dict.md Outdated
@AlexWaygood
Copy link
Copy Markdown
Member Author

Thank you for the equally exhaustive review! 😃

@AlexWaygood AlexWaygood enabled auto-merge (squash) March 12, 2026 16:35
@AlexWaygood AlexWaygood merged commit 04229cf into main Mar 12, 2026
46 checks passed
@AlexWaygood AlexWaygood deleted the alex-carl/pep-728 branch March 12, 2026 16:40
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

testing Related to testing Ruff itself ty Multi-file analysis & type inference

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants