Repository navigation
Description
User impact
Reading an example's docstring through help(), pydoc, or an IDE hover shows garbled command examples: multi-line shell commands collapse onto one line with the \ continuations silently removed. For example, the Usage block of code_generation_and_execution_bash.py renders as:
uv run python docs/examples/requirements/code_generation_and_execution_bash.py --workspace /path/to/workspace
instead of the intended two-line command. The files compile and run normally — this is a documentation rendering defect only. GitHub source view shows the raw text correctly, and the docs site is unaffected (example docstrings are not rendered by the docs pipeline).
Mechanism
\<newline> inside a non-raw string literal is a line-continuation escape: Python consumes both characters at compile time, so the docstring text stored in __doc__ never contains them. A docstring that documents a shell continuation must either:
- be a raw string (
r"""— used bydocs/examples/requirements/code_generation_and_execution.py), or - double the backslashes (
\\— used bydocs/examples/m_serve/multimodal-audio/m_serve_example_multimodal_audio_llama_server.py).
Neither ruff check (default rule selection) nor ruff check --select W605 flags this, because \<newline> is a valid escape sequence — W605 only fires on invalid ones. The failure is completely silent.
Occurrences
Non-raw module docstrings containing lone \-newline sequences (verified by AST analysis and rendered output):
| File | Lines | Escapes |
|---|---|---|
docs/examples/requirements/code_generation_and_execution_bash.py |
37, 41 | 2 |
docs/examples/granite-switch/answerability_openai.py |
8–9 | 2 |
docs/examples/granite-switch/hallucination_detection_openai.py |
8–9 | 2 |
docs/examples/granite-switch/manual_adapter_loading.py |
20–21 | 2 |
test/backends/test_audio_openai.py |
11–21 | 11 |
The first row is introduced by #1766 (fixing it there is optional — this issue tracks all occurrences). The rest pre-date that PR.
Suggested fix
Per file: prefix the module docstring with r, or double the backslashes. Both conventions already exist in the repo (links above).
To prevent recurrence, a small pre-commit hook could parse each .py file with ast and flag module docstrings that are non-raw and contain a lone \ immediately before a newline.
Verifying the fix
Render the docstring through the consumer path and check the continuation survives, e.g.:
import inspect
assert "--workspace" in inspect.getdoc(module).splitlines()[-1] # line ends with \
Activity
madhusudhan1260 commentedon Nov 2, 2026
Hi! I'd like to work on this issue — could you assign it to me?
I've reproduced it on current
main: rendering the module docstrings withinspect.getdoc/ast.get_docstringcollapses the\-continued commands onto one line in all five files listed. My plan is to switch those five module docstrings to raw strings (r"""), matching the convention already used incode_generation_and_execution.py, and verify each one by checking that the rendered docstring keeps the trailing\on the continued lines.I'll keep the PR limited to those five docstrings. Would you also like the small
ast-based pre-commit check you suggested included in the same PR, or would you prefer that as a separate follow-up?AngeloDanducci commentedon Nov 5, 2026
@madhusudhan1260 Hi, thanks for the interest. Assigned!