Repository navigation
feat(http-client-python): support P1 inline discriminated unions - #12285
Libba Lawrence (l0lawrence) wants to merge 1 commit into
Conversation
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
commit: |
Python emitter diffBaseline
Informational check (eng/emitter-diff); does not block the PR. |
|
All changed packages have been documented.
Show changes
|
|
You can try these changes here
|
Summary
Implement the Python P1 inline discriminated-union shape described in Azure/typespec-azure#5703 (section 2). This is a scoped Python implementation, not a resolution of the complete cross-language issue.
@discriminated(#{ envelope: "none" })on unions with an explicit model constraint and nominal model variants declaring matching required literal discriminator properties.Annotated[Union[...], _DiscriminatedUnion(...)]metadata for union-local deserialization rather than replacing the union with its base model or modifying shared model registrations.DeserializationErrorrather than selecting the first variant.@discriminatorhierarchies. Add regression coverage, README documentation, and a feature changelog.Compatibility and scope
Installed TCGC 0.73.0 exposes
discriminatedOptionsbut notSdkUnionType.baseType. Read the compiler's explicitUnion.baseTypeconstraint and match SDK model ancestry against it; do not infer a common ancestor. The sample requires the compiler's experimentalunion-extendsfeature.Initial support targets the default DPG model mode and explicit-base nominal variants. P2 object envelopes, default variants, structural variants, unions without an explicit model constraint, and variants without matching literal tags are unsupported and receive an explicit diagnostic. Existing skipped envelope/Spector scenarios remain untouched.
Validation
tscandpython -m build --wheel --no-isolation), avoiding dependency bootstrapping/downloads.vitest run --config emitter/vitest.config.ts --testTimeout 20000).pnpm format, andgit diff --checkpassed.Baseline caveats
test_models_mode_typeddict_does_not_write_empty_models_folder: its existing model-package scaffolding failure was reproduced with baselineCombinedTypefromHEADbefore implementation was committed.