Repository navigation
fix(python): escape quotes in enum documentation - #11897
Libba Lawrence (l0lawrence) merged 5 commits into
Conversation
|
Azure Pipelines: Successfully started running 1 pipeline(s). 1 pipeline(s) were filtered out due to trigger conditions. There may be pipelines that require an authorized user to comment /azp run to run. |
There was a problem hiding this comment.
🟡 Changes recommended
Enum descriptions rendered as Literal[...] in types.py.jinja2 still use unescaped wrap_string inside """...""", leaving the same triple-quote breakout risk in typeddict mode.
Once you've addressed the issues Copilot identified, you can request another Copilot review.
Pull request overview
Fixes a Python emitter correctness issue where enum/enum-member documentation containing """ can prematurely terminate generated docstrings, causing subsequent text to be treated as executable Python at import time.
Changes:
- Add a reusable
wrap_docstringJinja macro that escapes double quotes after existing wrapping/backslash escaping. - Use
wrap_docstringfor enum class and enum member docstrings inenum.py.jinja2. - Add regression tests that parse the formatted Python AST to ensure documentation stays within a string literal, plus a
.chronusfix entry.
File summaries
| File | Description |
|---|---|
| packages/http-client-python/tests/unit/test_enum_docstrings.py | Adds AST-based regressions ensuring enum docs remain string literals even with embedded """, backslashes, and trailing quotes. |
| packages/http-client-python/generator/pygen/codegen/templates/operation_tools.jinja2 | Introduces wrap_docstring macro to escape quotes after wrapping. |
| packages/http-client-python/generator/pygen/codegen/templates/enum.py.jinja2 | Switches enum and enum member docstring emission to the new wrap_docstring helper. |
| .chronus/changes/escape-python-enum-docstrings.md | Records a fix changeset for @typespec/http-client-python. |
Review details
- Files reviewed: 4/4 changed files
- Comments generated: 1
- Review effort level: Lite
💡 Configure MCP servers for context-aware, tailored reviews. Learn more in the docs.
Cover Literal enum rendering with the same AST and documentation-preservation checks as class and member docstrings. Assisted-by: OpenAI Codex (model: GPT-6 Astra, autonomous)
|
Posted on behalf of RKS (@rksharma-owg) by OpenAI Codex. Addressed the TypedDict/Literal enum path in b89dbca: Package build/wheel creation, all 23 emitter tests, targeted Pylint/Black checks, and full Azure/unbranded SDK regeneration passed. Regeneration produced no generated-file changes. The focused Python tests use |
There was a problem hiding this comment.
🟢 Approval recommended
The change is narrowly scoped to enum docstring rendering, includes a reusable helper, adds targeted regression tests that would fail on reversion, and includes an appropriate .chronus fix entry.
Review details
- Files reviewed: 5/5 changed files
- Comments generated: 0 new
- Review effort level: Lite
|
Hi @RKS (@rksharma-owg). Your PR has had no update for 14 days and it is marked as a stale PR. If it is not updated within 14 additional days, the PR will automatically be closed. If you want to refresh the PR, please remove the |
|
The PR remains active, and the reported checks pass on the current head (b89dbca). I tried to remove the |
commit: |
|
All changed packages have been documented.
Show changes
|
|
RKS (@rksharma-owg) thanks for the pr, can you merge the most recent main into your pr to unblock the CI run |
|
Merged current Fork preflight on that exact commit passed on Linux and Windows, including regeneration, generated tests, emitter tests, type checks, lint, and formatting. The new upstream workflows for |
Python emitter diffBaseline Diff summary: 2 file(s), +4 / -4 Rendered diff: inline on the run summary, or the emitter-diff-html artifact. Informational check (eng/emitter-diff); does not block the PR. |


Enum and enum member documentation containing triple quotes can terminate its generated Python docstring. For syntactically valid input, the formatter accepts the following documentation as class-body statements; trailing single quotes can also make member docstrings invalid Python.
Add a reusable docstring-wrapping macro that escapes quotes after the existing prose wrapping and backslash escaping, and use it for enum classes, members, and
Literal[...]enum descriptions in TypedDict output. This preserves ordinary documentation.Fixes #11881. Related to #10784; this change specifically covers quotes at the enum rendering boundary.
Validation:
git diff --checkpass. Linters were invoked directly to work around local optional-dependency and path-with-spaces problems in the wrapper.test_polymorphic_deserialization,test_enumeration_results_blobs_unwrapped, andtest_models_mode_typeddict_does_not_write_empty_models_folder. The local test run uses--confcutdir=tests/unitto avoid starting the unrelated mock API server.