Skip to content

fix(http-client-python): keep Sphinx docstring annotations out of trailing code blocks#11013

Open
l0lawrence wants to merge 3 commits into
microsoft:mainfrom
l0lawrence:l0lawrence/sphinx-codeblock-period
Open

fix(http-client-python): keep Sphinx docstring annotations out of trailing code blocks#11013
l0lawrence wants to merge 3 commits into
microsoft:mainfrom
l0lawrence:l0lawrence/sphinx-codeblock-period

Conversation

@l0lawrence

Copy link
Copy Markdown
Member

Why

Follow-up to #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).

…iling code blocks

Append annotations like Required. as their own paragraph after a trailing RST code block, and skip the sentence-ending period when a description ends with a code block so it no longer lands inside the rendered literal block.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
@microsoft-github-policy-service microsoft-github-policy-service Bot added the emitter:client:python Issue for the Python client emitter: @typespec/http-client-python label Jun 17, 2026
@pkg-pr-new

pkg-pr-new Bot commented Jun 17, 2026

Copy link
Copy Markdown

Open in StackBlitz

npm i https://pkg.pr.new/@typespec/http-client-python@11013

commit: 3d405d9

@github-actions

github-actions Bot commented Jun 17, 2026

Copy link
Copy Markdown
Contributor

All changed packages have been documented.

  • @typespec/http-client-python
Show changes

@typespec/http-client-python - fix ✏️

Place docstring annotations such as Required. on their own paragraph after a trailing RST code block and stop appending a sentence period inside the block. Previously the period landed on the code block's last line (e.g. ].) and Required. was jammed onto the lead-in sentence, both of which broke Sphinx rendering.

l0lawrence and others added 2 commits June 17, 2026 10:25
… inline marker mentions

Require the .. code-block:: directive to start its own line so an inline mention in prose is not mistaken for a trailing code block. Add tests covering multiple code blocks and the inline-mention case.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
@azure-sdk-automation

azure-sdk-automation Bot commented Jun 17, 2026

Copy link
Copy Markdown

You can try these changes here

🛝 Playground 🌐 Website 🛝 VSCode Extension

@l0lawrence

Copy link
Copy Markdown
Member Author
image

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

emitter:client:python Issue for the Python client emitter: @typespec/http-client-python

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant