Repository navigation
[python] Fix Sphinx docstring rendering of annotations after code blocks - #10955
Merged
Yuchao Yan (msyyc) merged 3 commits intoJun 12, 2026
Merged
Yuchao Yan (msyyc) merged 3 commits into
Yuchao Yan (msyyc) merged 3 commits into
Conversation
…strings Required. and other annotations were appended after RST code blocks, breaking Sphinx rendering. They are now inserted into the prose before the code block. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
commit: |
Contributor
|
All changed packages have been documented.
Show changes
|
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
|
You can try these changes here
|
Member
Author
Libba Lawrence (l0lawrence)
marked this pull request as ready for review
June 11, 2026 00:54
Yuchao Yan (msyyc)
approved these changes
Jun 11, 2026
Libba Lawrence (l0lawrence)
added a commit
to l0lawrence/typespec
that referenced
this pull request
Jun 18, 2026
…iling code blocks (microsoft#11013) ## Why Follow-up to microsoft#10955. That change kept the broken `]. Required.` from rendering, but two related issues remained for docstrings whose description ends with an RST code block (e.g. `ToolChoiceAllowed.tools` in `azure-ai-projects`): 1. `Required.` was inserted into the prose right before the code block, so it landed on the lead-in sentence: `...might look like: Required.` followed by the block. That reads wrong. 2. `preprocess.update_description` still appended a sentence-ending `.` to the description, which landed on the code block's last content line (`]` -> `].`), corrupting the rendered literal block. ## What - Add a shared `description_ends_with_code_block` helper (in `pygen/utils.py`) that detects when a code block is the trailing content of a description. - `add_to_description`: when the description ends with a code block, append the annotation (`Required.`, default value, etc.) as its own paragraph **after** the block instead of inline. Chained annotations group onto that trailing paragraph. Behavior is unchanged when there is no trailing code block, or when prose follows the block. - `update_description`: skip the trailing-period append when the description ends with a code block, so no `.` is injected into the block. ## Result For `ToolChoiceAllowed.tools`: ` :ivar tools: A list of tool definitions ... might look like: .. code-block:: json [ ... ] Required. ` No `].` inside the block, and `Required.` sits cleanly on its own line. Covered by unit tests in `tests/unit/test_add_to_description.py` (10 tests, including the full `update_description` -> `add_to_description` pipeline). --------- Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Why
Fixes #10314. When a property or parameter description ended with a code block, the emitter appended annotations like
Required.to the very end of the string. With code blocks converted to RST.. code-block::, the annotation landed right after the closing]of a JSON block (]. Required.), which breaks Sphinx rendering.Approach
Annotations are added centrally in
add_to_description(inpygen/codegen/models/utils.py), used by bothproperty.pyandparameter.pyand other callers. That helper is now code-block aware: when the description contains.. code-block::, the annotation is inserted into the prose before the code block instead of being appended after it. Behavior is unchanged when there is no code block.Tests
Added
tests/unit/test_add_to_description.pycovering the empty, plain, single-code-block, and multiple-code-block cases.