-
Notifications
You must be signed in to change notification settings - Fork 323
[python] Add models-mode "typeddict" for input-only TypedDict model generation #8907
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Draft
Copilot
wants to merge
10
commits into
main
Choose a base branch
from
copilot/fix-6154722-381857226-169e8ee3-b9f9-4c02-bf29-41221d5df5b0
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Draft
[python] Add models-mode "typeddict" for input-only TypedDict model generation #8907
Copilot
wants to merge
10
commits into
main
from
copilot/fix-6154722-381857226-169e8ee3-b9f9-4c02-bf29-41221d5df5b0
Conversation
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
- Added "models-mode" option to PythonEmitterOptions with "typeddict" as a valid value - Created TypedDictModelSerializer class for generating TypedDict-based models - Added model_typeddict.py.jinja2 template for TypedDict model generation - Updated model serializer dispatch logic to support "typeddict" mode - Created TypedDictModelType class for TypedDict model types - Updated emitter to set model base field based on models-mode option Co-authored-by: msyyc <70930885+msyyc@users.noreply.github.com>
- Updated example_template to skip examples for typeddict mode - Added typeddict body parameter serialization handling - Updated need_utils_folder to include typeddict mode Co-authored-by: msyyc <70930885+msyyc@users.noreply.github.com>
- Added TypedDictModelType to imports in builder_serializer.py Co-authored-by: msyyc <70930885+msyyc@users.noreply.github.com>
- Updated declare_model to use 'total=False' to match template - Changed template to use 'is not None' instead of '!= None' Co-authored-by: msyyc <70930885+msyyc@users.noreply.github.com>
- Updated template to use serializer.declare_model() method
- Changed property check to use {% if model.properties %} for consistency
- Refactored builder_serializer to combine dpg and typeddict logic, reducing duplication
Co-authored-by: msyyc <70930885+msyyc@users.noreply.github.com>
Copilot
AI
changed the title
[WIP] [python] Add new models-mode "typeddict"
[python] Add models-mode "typeddict" for input-only TypedDict model generation
Nov 3, 2025
…-41221d5df5b0' and 'main' of https://github.com/microsoft/typespec into copilot/fix-6154722-381857226-169e8ee3-b9f9-4c02-bf29-41221d5df5b0
Contributor
|
❌ There is undocummented changes. Run The following packages have changes but are not documented.
Show changes |
Contributor
|
Hi @@copilot. Your PR has had no update for 30 days and it is marked as a stale PR. If it is not updated within 30 days, the PR will automatically be closed. If you want to refresh the PR, please remove the |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Labels
emitter:client:python
Issue for the Python client emitter: @typespec/http-client-python
stale
Mark a PR that hasn't been recently updated and will be closed.
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.
Implements alpha TypedDict support for issue #8800. Enables generating Python TypedDict classes instead of runtime model classes for input-only scenarios.
Changes
TypeScript Emitter
"typeddict"tomodels-modeoption enum inPythonEmitterOptionsemitModel()to dynamically set model base field from optionsPython Generator
TypedDictModelTypeclass - serializes as plaindict, usesisinstance(x, dict)checksTypedDictModelSerializer- generates TypedDict classes withtotal=Falsefor optional propertiesmodel_typeddict.py.jinja2template__init__.pyandbuilder_serializer.pyto handle typeddict modeUsage
Generates:
Limitations (Alpha)
Warning
Firewall rules blocked me from connecting to one or more addresses (expand for details)
I tried to connect to the following addresses, but was blocked by firewall rules:
telemetry.astro.buildIf you need me to access, download, or install something from one of these locations, you can either:
Original prompt
💬 We'd love your input! Share your thoughts on Copilot coding agent in our 2 minute survey.