Silently mangled docstrings: lone backslash line-continuations in non-raw docstrings collapse command examples
维护者通常 3 天内回复
@madhusudhan1260 已经在做这个了。
开始于 2026年11月5日。
评估
- 难度
- 2/5
- 预计耗时
- 1-3 小时
- 新手友好度
- 82/100
- Issue 类型
- 文档
- 描述清晰度
- 描述清楚
- 活跃度
- 活跃
- 技术栈
- python
调研方向
从 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 内容生成。
描述
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 \
- 主要语言
- Python
- 星标
- 1.8k
- 派生
- 161
- 平均合并
- 4 天 3 小时
- 30 天内合并 PR
- 45
环境准备
- 没有 Dockerfile 或 Docker Compose 文件
- 有 Pull Request 模板
- 阅读贡献指南
从这里开始
- 先读完整个 Issue,再读项目的贡献指南。
- 在 Issue 下留言说明你要接手 —— 这能避免两个人做同样的事。
- Fork 仓库,在一个分支上完成修改。
- 提交 Pull Request,并在描述里引用这个 Issue 编号。
generative-computing/mellea 的其他 Issue
-
bug
难度 2/5 1-3 小时 新手友好度 72/100
generative-computing/mellea#1864 ·
维护者通常 3 天内回复
-
bug: instruct() and react() replay tool-call turns without tool_calls可能已有人在做 @simonyang08 于 21 天前认领。 未关闭bug
难度 2/5 1-3 小时 新手友好度 85/100
generative-computing/mellea#1784 · 1 条评论 ·
维护者通常 3 天内回复
-
area/telemetry enhancement p2
难度 2/5 1-3 小时 新手友好度 66/100
generative-computing/mellea#1210 ·
维护者通常 3 天内回复
-
area/requirement area/stdlib enhancement p2
难度 2/5 1-3 小时 新手友好度 62/100
generative-computing/mellea#31 · 2 条评论 ·
维护者通常 3 天内回复
-
难度 5/5 一周以上 新手友好度 18/100
generative-computing/mellea#1863 ·
维护者通常 3 天内回复
查看 generative-computing/mellea 的全部 Issue
相似的 Issue
-
flaky: test_fire_returns_thread_per_http_entry_on_head waits 5 s per dispatch worker on busy shards未关闭status/accepted type/bug
难度 2/5 1-3 小时 新手友好度 74/100
维护者通常 1 天内回复
-
bug vector-store
难度 2/5 1-3 小时 新手友好度 85/100
维护者通常 1 天内回复
-
难度 2/5 1-3 小时 新手友好度 74/100
EverMind-AI/Raven#1413 ·
维护者通常 1 天内回复
-
Tests: parallel pyinstallcheck runs oversubscribe the machine through nested TBB and BLAS pools可能已有人在做 关联的 PR 仍在进行中或已合并。 未关闭
难度 2/5 1-3 小时 新手友好度 72/100
维护者通常 1 天内回复
-
难度 1/5 1 小时以内 新手友好度 86/100
ACCESS-NRI/containerised-environments-infra#143 ·
维护者通常 2 天内回复