Skip to content

[Python] Ensure necessary model imports#8006

Merged
pvaneck merged 4 commits into
microsoft:mainfrom
pvaneck:typespec-internal-model-imports
Aug 1, 2025
Merged

[Python] Ensure necessary model imports#8006
pvaneck merged 4 commits into
microsoft:mainfrom
pvaneck:typespec-internal-model-imports

Conversation

@pvaneck

@pvaneck pvaneck commented Jul 25, 2025

Copy link
Copy Markdown
Member

Internal models still get __init__ overloads and still need the necessary imports. This changes the conditional check to use need_init which is more appropriate.

This fixes the cases where all models are internal and Mapping and overload imports are missing in the generated _models.py file.

Internal models still get `__init__` overloads and still need the
necessary imports. This changes the conditional check to use `need_init`
which is more appropriate.

This fixes the cases where all models are internal and `Mapping` and
`overload` imports are missing in the generated `_models.py` file.

Signed-off-by: Paul Van Eck <paulvaneck@microsoft.com>
@microsoft-github-policy-service microsoft-github-policy-service Bot added the emitter:client:python Issue for the Python client emitter: @typespec/http-client-python label Jul 25, 2025
@github-actions

github-actions Bot commented Jul 25, 2025

Copy link
Copy Markdown
Contributor

All changed packages have been documented.

  • @typespec/http-client-python
Show changes

@typespec/http-client-python - fix ✏️

Ensure necessary typing imports for internal models

@azure-sdk

azure-sdk commented Jul 25, 2025

Copy link
Copy Markdown
Collaborator

You can try these changes here

🛝 Playground 🌐 Website 🛝 VSCode Extension

@msyyc

msyyc commented Jul 25, 2025

Copy link
Copy Markdown
Contributor

@pvaneck After CI pass, please follow https://gist.github.com/msyyc/98b366435dbb2cf6a927074efe4b1f47 to create related PR in autorest.python repo to make sure this PR brings no bad impact for downstream emitter.

Comment thread .chronus/changes/typespec-internal-model-imports-2025-6-25-1-29-21.md Outdated
@msyyc

msyyc commented Jul 30, 2025

Copy link
Copy Markdown
Contributor

Hi @pvaneck there is no code diff in Azure/autorest.python#3152. Could you share the context or real service case that this PR tries to fix?

@pvaneck

pvaneck commented Jul 30, 2025

Copy link
Copy Markdown
Member Author

Hey, @msyyc. I encountered the problem when constructing TypeSpec for the Azure.Monitor.Query service. This has a single operation, and in client.tsp, I have the operation marked as internal. This makes the associated models internal as well.

After emitting the Python, the generated _models.py was missing imports for Mapping and overload which were used throughout the code, causing a bunch of errors.

@pvaneck pvaneck added this pull request to the merge queue Jul 31, 2025
Merged via the queue into microsoft:main with commit 99dd5f1 Aug 1, 2025
37 checks passed
@pvaneck pvaneck deleted the typespec-internal-model-imports branch August 1, 2025 00:19
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

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants