[python] Fix Sphinx docstring rendering of annotations after code blocks#1
Closed
l0lawrence wants to merge 1 commit into
Closed
[python] Fix Sphinx docstring rendering of annotations after code blocks#1l0lawrence wants to merge 1 commit into
l0lawrence wants to merge 1 commit 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>
|
All changed packages have been documented.
Show changes
|
Owner
Author
|
Superseded by a PR targeting microsoft/typespec main. |
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 microsoft#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. This was one of the issues being worked around in @dargilco's post-processing script.Approach
The annotations are added centrally in
add_to_description(inpygen/codegen/models/utils.py), which is used by bothproperty.pyandparameter.py(and other callers). I made that helper code-block aware: when the description contains.. code-block::, the annotation is now inserted into the prose before the code block instead of being appended after it. Behavior is unchanged when there is no code block.This is a minimal, central fix so every caller benefits without touching individual call sites.
Tests
Added
tests/unit/test_add_to_description.pycovering the empty, plain, single-code-block, and multiple-code-block cases. The multi-block case verifies insertion happens before the first block.Note: 3 pre-existing unit failures in
test_model_base_serialization.py/test_model_base_xml_serialization.pyare unrelated to this change.