Silently mangled docstrings: lone backslash line-continuations in non-raw docstrings collapse command examples

未关闭 适合新手
#1,780 2 条评论 0 个 reaction 已指派 1 人 在 GitHub 查看

维护者通常 3 天内回复

@madhusudhan1260 已经在做这个了。

开始于 2026年11月5日。

评估

难度
2/5
预计耗时
1-3 小时
新手友好度
82/100
Issue 类型
文档
描述清晰度
描述清楚
活跃度
活跃
技术栈
python
领域
documentation

调研方向

从 docs/examples/requirements/code_generation_and_execution_bash.py 的第 37 和 41 行开始,此处用法块坍塌;相同的孤立 \-换行模式位于 docs/examples/granite-switch/answerability_openai.py (8-9)、hallucination_detection_openai.py (8-9)、manual_adapter_loading.py (20-21) 和 test/backends/test_audio_openai.py (11-21)。为每个模块 docstring 添加前缀 r(如 docs/examples/requirements/code_generation_and_execution.py 中),或加倍反斜杠,以匹配 docs/examples/m_serve/multimodal-audio/m_serve_example_multimodal_audio_llama_server.py 已使用的约定。完成状态类似于每个 docstring 通过 inspect.getdoc 渲染且续行保持完整,如验证片段所示。

由索引模型根据 Issue 内容生成。

描述

good first issue p2

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 by docs/examples/requirements/code_generation_and_execution.py), or
  • double the backslashes (\\ — used by docs/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 \
主要语言
Python
星标
1.8k
派生
161
平均合并
4 天 3 小时
30 天内合并 PR
45

环境准备

从这里开始

  1. 先读完整个 Issue,再读项目的贡献指南。
  2. 在 Issue 下留言说明你要接手 —— 这能避免两个人做同样的事。
  3. Fork 仓库,在一个分支上完成修改。
  4. 提交 Pull Request,并在描述里引用这个 Issue 编号。

generative-computing/mellea 的其他 Issue

查看 generative-computing/mellea 的全部 Issue

相似的 Issue

更多 Python Issue

把新 issue 发到你的邮箱

精选适合新手参与的 GitHub issue 摘要。