[python] Fix named single-member union aliases - #11933
Open
Libba Lawrence (l0lawrence) wants to merge 1 commit into
Open
[python] Fix named single-member union aliases#11933Libba Lawrence (l0lawrence) wants to merge 1 commit into
Libba Lawrence (l0lawrence) wants to merge 1 commit into
Conversation
Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
Libba Lawrence (l0lawrence)
requested review from
ChenxiJiang333,
catalinaperalta,
iscai-msft,
Kashif Khan (kashifkhan),
Laurent Mazuel (lmazuel),
Mark Cowlishaw (markcowl),
Yuchao Yan (msyyc),
Chenjie Shi (tadelesh),
Timothee Guerin (timotheeguerin) and
Jeff Fisher (xirzec)
as code owners
September 10, 2026 22:34
Copilot started reviewing on behalf of
Libba Lawrence (l0lawrence)
September 10, 2026 22:35
View session
commit: |
Contributor
|
All changed packages have been documented.
Show changes
|
Contributor
There was a problem hiding this comment.
🔵 Needs a closer look
Regression coverage should exercise the full preprocessing path and assert distinct overload body types.
Pull request overview
Fixes Python generation for named single-member unions and avoids invalid lone overloads.
Changes:
- Emits named unions as explicit
TypeAliasdeclarations. - Preserves concrete method annotations and multi-member overloads.
- Adds regression tests and a changelog entry.
File summaries
| File | Summary |
|---|---|
packages/http-client-python/tests/unit/test_typeddict.py |
Tests single- and multi-member union aliases. |
packages/http-client-python/tests/unit/test_typeddict_overloads.py |
Tests overload generation behavior. |
packages/http-client-python/generator/pygen/preprocess/__init__.py |
Skips lone overload generation. |
packages/http-client-python/generator/pygen/codegen/templates/unions.py.jinja2 |
Emits explicit type aliases. |
packages/http-client-python/generator/pygen/codegen/serializers/unions_serializer.py |
Imports TypeAlias. |
.chronus/changes/l0lawrence-single-union-aliases-2026-09-10-15-30-27.md |
Records the bug fix. |
Review details
Suppressed comments (3)
packages/http-client-python/generator/pygen/preprocess/init.py:102
- The new regression cases call
add_overloads_for_body_paramdirectly with hand-built YAML, so they never exercise the shippedPreProcessPlugin.update_operationpath that invokes this branch or serialize the resulting concrete method. A failure in that integration could still leave the named body replaced or the method signature without"_unions.GenerateAgentRequest"; add a test through the real preprocessing/operation serialization entrypoint.
and len(body_types) > 1
and len(body_types) > len(yaml_data["overloads"])
packages/http-client-python/tests/unit/test_typeddict_overloads.py:109
- This regression test calls
add_overloads_for_body_paramdirectly, while the shipped path invokes it fromPreProcessPlugin.update_operationafterupdate_parameterandadd_body_param_type(generator/pygen/preprocess/__init__.py:694-708). It therefore never verifies that the full preprocessing flow still renders the concrete operation with the named alias; add a test through that entry point (or the generator) and assert the emitted signature.
add_overloads_for_body_param(yaml_data)
assert yaml_data["overloads"] == []
assert yaml_data["bodyParameter"]["type"] is named_union
assert yaml_data["bodyParameter"]["type"]["name"] == "GenerateAgentRequest"
packages/http-client-python/tests/unit/test_typeddict_overloads.py:118
- Checking only the overload count does not enforce the stated per-variant behavior: a regression that appends two overloads for the same body member would still pass. Assert that the overload body types match the two distinct entries in the combined type.
add_overloads_for_body_param(yaml_data)
assert len(yaml_data["overloads"]) == 2
- Files reviewed: 6/6 changed files
- Comments generated: 0
- Review effort level: Lite
💡 Configure MCP servers for context-aware, tailored reviews. Learn more in the docs.
|
You can try these changes here
|
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
TypeAliasdeclarations, including single-member unionsValidation
npm run buildnpm run formatnpm run lint -- --generatornpm run lint -- --emitterpnpm format