Skip to content

[Python] Ensure necessary model imports#8006

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

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

Conversation

@pvaneck
Copy link
Member

@pvaneck pvaneck commented Jul 25, 2025

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
Copy link
Contributor

github-actions bot commented Jul 25, 2025

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
Copy link
Collaborator

azure-sdk commented Jul 25, 2025

You can try these changes here

🛝 Playground 🌐 Website 🛝 VSCode Extension

@msyyc
Copy link
Contributor

msyyc commented Jul 25, 2025

@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.

@msyyc
Copy link
Contributor

msyyc commented Jul 30, 2025

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
Copy link
Member Author

pvaneck commented Jul 30, 2025

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

Comments