Skip to content

fix(http-client-python): removing duplicate union aliases and preserve overload parameter types - #12017

Open
Libba Lawrence (l0lawrence) wants to merge 10 commits into
mainfrom
l0lawrence-single-union-aliases
Open

Libba Lawrence (l0lawrence) wants to merge 10 commits into
mainfrom
l0lawrence-single-union-aliases

Conversation

@l0lawrence

@l0lawrence Libba Lawrence (l0lawrence) commented Sep 18, 2026

Copy link
Copy Markdown
Member

Fixes two more bugs in the Python emitter (@typespec/http-client-python, pygen) surfaced in generated azure-ai-projects SDK code:

  1. Duplicate named union aliases_unions.py could emit the same named union alias more than once. UnionsSerializer.named_unions now deduplicates by alias name so each named union produces a single TypeAlias declaration.
  2. Shifted overload parameter typesadd_overload filtered out flattened body parameters before reattaching shared type objects, so zip-based positional alignment against the original operation could assign the wrong type to trailing parameters. The type reattachment now runs before the flattened-parameter filter, preserving correct types on the remaining parameters.

Note

  • Conditional request header pairs (If-Match / If-None-Match). when an operation declares one of the conditional headers we add its pair since MatchConditions can be selected

Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
@pkg-pr-new

pkg-pr-new Bot commented Sep 18, 2026

Copy link
Copy Markdown

Open in StackBlitz

npm i https://pkg.pr.new/@typespec/http-client-python@12017

commit: cd1ce57

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟢 Approval recommended

No unresolved review issues remain, and validation passed.

Pull request overview

Fixes Python generator regressions involving named unions, overload type alignment, and ETag handling.

Changes:

  • Deduplicates named union aliases.
  • Preserves parameter types after flattening.
  • Handles required and optional ETag APIs correctly.
  • Adds focused regression tests and changelog documentation.
File summaries
File Reviewed change
packages/http-client-python/tests/unit/test_typeddict.py Tests duplicate alias elimination.
packages/http-client-python/tests/unit/test_typeddict_overloads.py Tests overload type preservation.
packages/http-client-python/tests/unit/test_preprocess_etag.py Tests required and optional ETag behavior.
packages/http-client-python/generator/pygen/preprocess/__init__.py Updates overload typing and ETag preprocessing.
packages/http-client-python/generator/pygen/codegen/templates/unions.py.jinja2 Renders deduplicated unions.
packages/http-client-python/generator/pygen/codegen/serializers/unions_serializer.py Deduplicates named unions.
.chronus/changes/python-union-etag-regressions-2026-09-18.md Records the package fix.
Review details
  • Files reviewed: 7/7 changed files
  • Comments generated: 0
  • Review effort level: Lite

💡 Configure MCP servers for context-aware, tailored reviews. Learn more in the docs.

@l0lawrence
Libba Lawrence (l0lawrence) marked this pull request as draft September 18, 2026 17:03
@github-actions

github-actions Bot commented Sep 18, 2026

Copy link
Copy Markdown
Contributor

All changed packages have been documented.

  • @typespec/http-client-python
Show changes

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

Prevent duplicate named union aliases, and preserve parameter types in generated body overloads when a flattened parameter is filtered out.

Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
@github-actions

github-actions Bot commented Sep 18, 2026

Copy link
Copy Markdown
Contributor

Python emitter diff

Baseline gh:004bc010733c5f0d036a07d4a748722c4012d9a5 vs this PR.

No changes to generated output.

Rendered diff: inline on the run summary, or the emitter-diff-html artifact.

Informational check (eng/emitter-diff); does not block the PR.

@l0lawrence Libba Lawrence (l0lawrence) changed the title [python] Fix named union and ETag overload regressions [python] Fix duplicate union and overload typing Sep 18, 2026
@azure-sdk-automation

azure-sdk-automation Bot commented Sep 18, 2026

Copy link
Copy Markdown

You can try these changes here

🛝 Playground 🌐 Website 🛝 VSCode Extension

Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
Collapse duplicate named unions by alias name using an insertion-ordered dict instead of raising on conflicting definitions. Update the test to assert a single alias is emitted (first wins).

Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
Synthesize the missing ETag partner as a real wire header with canonical HTTP casing (If-Match/If-None-Match) instead of a non-wire keyword parameter. At most one side serializes per call, gated by match_condition, so no undeclared header is sent. Remove the now-dead per-overload etag recursion (overloads inherit the reconciled pair via add_overload's deep copy) and revert the keyword-only method_location special case.

Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
Scope the PR to two fixes: deduplicate named union aliases, and reattach shared parameter type objects before filtering flattened parameters in add_overload so trailing parameter types are not shifted. Removes the earlier conditional-header casing synthesis change and its tests.

Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
@l0lawrence Libba Lawrence (l0lawrence) changed the title [python] Fix duplicate union and overload typing fix(http-client-python): dedupe named union aliases and preserve overload parameter types Sep 18, 2026
@l0lawrence Libba Lawrence (l0lawrence) changed the title fix(http-client-python): dedupe named union aliases and preserve overload parameter types fix(http-client-python): removing duplicate union aliases and preserve overload parameter types Sep 18, 2026
@l0lawrence
Libba Lawrence (l0lawrence) marked this pull request as ready for review September 18, 2026 22:07
Copilot AI review requested due to automatic review settings September 18, 2026 22:07

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copilot review overview

🔵 Needs a closer look

Add integration coverage through the production preprocessing path.

Review effort: Lite
Findings: None

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.

2 participants