Repository navigation
[http-client-python][ICM] Escape generated string literals and wire names - #12342
Conversation
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com> Copilot-Session: ecfba725-b27d-416c-95a6-bc48a498ca8f
commit: |
|
All changed packages have been documented.
Show changes
|
There was a problem hiding this comment.
🟡 Changes recommended
Targeted verification confirms that downstream template rendering still corrupts escaped values and can produce invalid Python examples.
1 open issue
What changed in this PR
This PR updates the Python client generator to serialize specification strings as Python literals, preserving special characters and treating expression-like text as data.
Changes:
- Replace manual quoting in string declarations, discriminator arguments, initializers, and template values.
- Add regression tests for literal preservation and generated model behavior; adjust TypedDict quotation expectations.
- Add a Python emitter fix changelog.
| File | Description |
|---|---|
packages/http-client-python/tests/unit/test_typeddict.py |
Update two expectations for equivalent literal quoting. |
packages/http-client-python/tests/unit/test_string_literals.py |
Add special-character and discriminator regression coverage. |
packages/http-client-python/generator/pygen/codegen/serializers/model_serializer.py |
Escape discriminator initializers and class arguments. |
packages/http-client-python/generator/pygen/codegen/models/primitive_types.py |
Serialize string declarations with repr. |
packages/http-client-python/generator/pygen/codegen/models/model_type.py |
Escape discriminator values in template representations. |
.chronus/changes/python-discriminator-string-literals-2026-10-22.md |
Document the Python string-literal fix. |
Review effort: Balanced
Python emitter diffBaseline 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. |
|
You can try these changes here
|
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com> Copilot-Session: ecfba725-b27d-416c-95a6-bc48a498ca8f
|
CI investigation: the optional Azure/typespec-azure integration check fails on both the original and follow-up heads, outside this Python change. Latest run: https://github.com/microsoft/typespec/actions/runs/39734024339/job/119675416698. The downstream playground imports registerMonacoDefaultWorkersForVite from @typespec/playground, but the current API is exported from @typespec/playground/vite/workers. The downstream import needs updating; this PR does not change playground exports or bypass the check. All other current-head checks have now passed. Tracked in Azure/typespec-azure#5806; monitoring continues. |
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
iscai-msft
left a comment
There was a problem hiding this comment.
there are a lot of diffs in the generated code, and i think most of them we don't want to change. i believe there's also a testserver case for the "too-long example code", you could see what changes when you remove the code in jinja
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com> Copilot-Session: aaeb82ef-b4f1-4a88-9442-edd2ea4061cf
Merge main to align core dependency catalog references with Azure integration. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com> Copilot-Session: aaeb82ef-b4f1-4a88-9442-edd2ea4061cf
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com> Copilot-Session: aaeb82ef-b4f1-4a88-9442-edd2ea4061cf
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com> Copilot-Session: aaeb82ef-b4f1-4a88-9442-edd2ea4061cf
Replace escaping flags with explicit multiline and inline content helpers. Keep client/config delimiters in templates and preserve generated source output. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com> Copilot-Session: aaeb82ef-b4f1-4a88-9442-edd2ea4061cf

Summary
Fix Python string-literal generation described in this report and #12405.
Validation
pnpm format, and emitter/generator lint passed.The deselected test,
test_models_mode_typeddict_does_not_write_empty_models_folder, fails identically against an isolated copy of the unchanged PR-head generator. It is unrelated to string serialization and is not changed here. Local Python runtime validation used Python 3.13.