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

Aperta Adatta ai principianti
#1,780 2 commenti 0 reazioni 1 assegnatario Vedi su GitHub

I maintainer di solito rispondono entro 3 giorni

@madhusudhan1260 ci sta già lavorando.

Dal 5/11/2026.

Valutazione

Difficoltà
2/5
Tempo stimato
1-3 ore
Idoneità per principianti
82/100
Tipo di issue
Documentazione
Chiarezza
Specificata chiaramente
Stato di attività
Attiva
Stack tecnologico
python
Ambito
documentation

Direzione di ricerca

Inizia con docs/examples/requirements/code_generation_and_execution_bash.py righe 37 e 41, dove il blocco di utilizzo collassa; lo stesso pattern \-nuova riga isolato si trova in docs/examples/granite-switch/answerability_openai.py (8-9), hallucination_detection_openai.py (8-9), manual_adapter_loading.py (20-21) e test/backends/test_audio_openai.py (11-21). Anteponi r a ogni docstring di modulo (come in docs/examples/requirements/code_generation_and_execution.py) o raddoppia i backslash, seguendo la convenzione già usata in docs/examples/m_serve/multimodal-audio/m_serve_example_multimodal_audio_llama_server.py. Fatto appare come ogni docstring reso con le continuazioni intatte tramite inspect.getdoc, come mostra lo snippet di verifica.

Scritto dal modello di indicizzazione a partire dal testo della issue.

Descrizione

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 \
Lingua principale
Python
Stelle
1.8k
Fork
161
Merge medio
4g 3h
PR unite (30g)
45

Preparare l'ambiente

Come iniziare

  1. Leggi tutta la issue e poi la guida ai contributi del progetto.
  2. Commenta sulla issue per dire che te ne occupi tu — evita che due persone facciano lo stesso lavoro.
  3. Fai un fork del repository e lavora su un branch.
  4. Apri una pull request che faccia riferimento al numero della issue.

Altre issue di generative-computing/mellea

Tutte le issue di generative-computing/mellea

Issue simili

Altre issue su Python

Ricevi le nuove issue nella tua casella

Un breve riepilogo di issue GitHub adatte ai principianti.