Repository navigation
[http-client-python] Escape generated discriminator string literals - #12341
Yuchao Yan (msyyc) wants to merge 1 commit into
Conversation
Co-authored-by: Copilot <[email protected]> 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 formatting still corrupts escaped discriminator values or produces invalid Python.
1 open issue
What changed in this PR
This PR improves Python client generation by serializing specification strings as Python literals rather than manually adding quotes.
Changes:
- Use
repr()for string constants, discriminator declarations, initializers, and template values. - Add regression coverage for special characters and expression-like strings.
- Update quotation-style expectations and add a fix changelog.
| File | Description |
|---|---|
packages/http-client-python/tests/unit/test_typeddict.py |
Adjust expected literal quotation style. |
packages/http-client-python/tests/unit/test_string_literals.py |
Add literal and discriminator regression tests. |
packages/http-client-python/generator/pygen/codegen/serializers/model_serializer.py |
Escape discriminator class arguments and initializers. |
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 |
Serialize discriminator template values with repr(). |
.chronus/changes/python-discriminator-string-literals-2026-10-22.md |
Document the Python emitter fix. |
Review effort: Balanced
| } | ||
| if self.discriminator and self.discriminator_value: | ||
| representation[f'"{self.discriminator.wire_name}"'] = f'"{self.discriminator_value}"' | ||
| representation[f'"{self.discriminator.wire_name}"'] = repr(self.discriminator_value) |
|
You can try these changes here
|
Python emitter diffBaseline Diff summary: 1174 file(s), +5813 / -5821 Rendered diff: inline on the run summary, or the emitter-diff-html artifact. Informational check (eng/emitter-diff); does not block the PR. |

No description provided.