feat: Implement NewTypedDict[*Ps: Member] type operator#23
Merged
Conversation
Add the NewTypedDict type operator as specified in PEP 827 for creating TypedDict types from Member type arguments. Changes: - Add NewTypedDict class definition to typing.py - Add evaluator in _eval_operators.py - Add comprehensive tests (7 test cases) - Handle NotRequired qualifier for optional fields Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Use typing.cast to make mypy understand that TypedDict is callable when creating a NewTypedDict type. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
- Handle ReadOnly qualifier in addition to NotRequired - Support multiple qualifiers (ReadOnly + NotRequired) - Add tests for ReadOnly functionality Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Implements the
NewTypedDict[*Ps: Member]type operator as specified in PEP 827 for creating TypedDict types dynamically from Member type arguments.Changes
typing.py): AddedNewTypedDictclass definition with docstring and usage examples_eval_operators.py): Implemented_eval_NewTypedDictfunction that:NotRequiredqualifier for optional fieldstest_type_eval.py): Added 7 comprehensive test casesUsage Examples
Test Cases
test_newtypeddict_basic- Basic TypedDict creationtest_newtypeddict_single_field- Single field creationtest_newtypeddict_preserves_types- Type preservationtest_newtypeddict_with_complex_types- Complex types (list, dict)test_newtypeddict_multiple_fields- Multiple fieldstest_newtypeddict_optional_field- NotRequired qualifier handlingtest_newtypeddict_with_iter_attrs- Integration with Iter/AttrsRelated Issue
Closes #18
🤖 Generated with Claude Code