ValueError: start precedes previous end, for a backslash line continuation after a reformatted docstring
I maintainer di solito rispondono entro 1 giorno
Nessuno ha ancora preso questa issue.
Valutazione
- Difficoltà
- 3/5
- Tempo stimato
- 1-2 giorni
- Idoneità per principianti
- 68/100
Direzione di ricerca
Inizia con docformatter/format.py, in particolare _do_format_code e _do_update_token_indices, quindi esegui il riproduttore t.py fornito con --check. Aggiungi o esamina il test di regressione menzionato nell’issue e verifica che le continuazioni con backslash dopo docstring riformattate non generino più un tokenizer ValueError nelle versioni di Python supportate.
Scritto dal modello di indicizzazione a partire dal testo della issue.
Descrizione
docformatter 1.7.8 (and current master, d5c7b77) crashes with the tokenizer ValueError whenever a docstring edit shifts the lines of a file that contains a backslash line continuation somewhere after that docstring. Running docformatter --check over the Python 3.14 standard library hits it in _sitebuiltins.py, pdb.py, tokenize.py, ctypes/util.py, email/feedparser.py, encodings/utf_16.py, encodings/utf_32.py, encodings/utf_8_sig.py and http/cookies.py.
Reproducer
class A:
"""Doc."""
x = 1 \
+ 2
$ docformatter --check t.py
Traceback (most recent call last):
...
File ".../docformatter/format.py", line 919, in _do_format_code
_code = tokenize.untokenize(self.new_tokens)
File ".../tokenize.py", line 178, in add_whitespace
raise ValueError("start ({},{}) precedes previous end ({},{})"
ValueError: start (4,8) precedes previous end (4,9)
A module docstring followed directly by x = 1 \ / + 2 fails the same way. Adding a blank line after the docstring (so nothing needs to be inserted) makes it pass, and so does writing the continuation with parentheses instead of a backslash. Same result on Python 3.11 and 3.14.
Cause
docformatter inserts the missing blank line after the docstring, which shifts every following token down one row. _do_update_token_indices() then recomputes positions and decides whether a token continues the previous token's row with
is_same_position = tokens[i].start[0] == tokens[i - 1].end[0]
where tokens[i - 1] has already been shifted and tokens[i] has not. For a parenthesised continuation an NL token sits between the two physical lines, so the comparison is never reached; a backslash continuation produces no NL token, so for the first token on the continuation line the un-shifted row happens to equal the shifted row of the previous token, the token is treated as being on the same row, and its start ((4,8)) ends up before the previous token's end ((4,9)).
I have a fix (treat a token as starting a new row when the previous token's physical line ends with \) with a regression test; PR follows.
- Lingua principale
- Python
- Stelle
- 598
- Fork
- 95
- Merge medio
- 2g 3h
- PR unite (30g)
- 11
Preparare l'ambiente
Questo progetto non fornisce container di sviluppo, Dockerfile né guida per i contributori, quindi l'ambiente è a tuo carico: parti dal suo README e consulta la nostra guida al primo contributo per i passaggi generali.
Come iniziare
- Leggi tutta la issue e poi la guida ai contributi del progetto.
- Commenta sulla issue per dire che te ne occupi tu — evita che due persone facciano lo stesso lavoro.
- Fai un fork del repository e lavora su un branch.
- Apri una pull request che faccia riferimento al numero della issue.
Altre issue di PyCQA/docformatter
-
1.7.8 crashes with a tokenize ValueError on a multi-line f-string inside parenthesesForse di nuovo libera @adityaanikam l’ha presa 68 giorni fa e non c’è nessuna pull request aperta. ApertaC: convention P: bug U: high
Difficoltà 3/5 1-2 giorni Idoneità per principianti 74/100
PyCQA/docformatter#367 · 1 commento ·
I maintainer di solito rispondono entro 1 giorno
-
1.7.8 rewrites the contents of a non-docstring triple-quoted string, silently changing its valueApertaC: convention P: bug U: high
Difficoltà 3/5 1-2 giorni Idoneità per principianti 72/100
PyCQA/docformatter#366 ·
I maintainer di solito rispondono entro 1 giorno
-
C: stakeholder P: enhancement U: low
Difficoltà 3/5 1-2 giorni Idoneità per principianti 65/100
PyCQA/docformatter#346 ·
I maintainer di solito rispondono entro 1 giorno
-
C: convention P: bug U: high
Difficoltà 3/5 1-2 giorni Idoneità per principianti 48/100
PyCQA/docformatter#345 · 1 reazione ·
I maintainer di solito rispondono entro 1 giorno
-
C: convention P: bug U: high
Difficoltà 3/5 1-2 giorni Idoneità per principianti 55/100
PyCQA/docformatter#315 · 1 commento ·
I maintainer di solito rispondono entro 1 giorno
Tutte le issue di PyCQA/docformatter
Issue simili
-
Difficoltà 2/5 1-3 ore Idoneità per principianti 78/100
-
[Bug] to_ical lexicographical/default sorting moves URL property between two X-WR- propertiesAperta
Difficoltà 2/5 1-3 ore Idoneità per principianti 68/100
collective/icalendar#1968 · 1 commento ·
I maintainer di solito rispondono entro 1 giorno
-
Deferred from #1869: Complete the companion pytest guardrail update noted in the PR description...Aperta
Difficoltà 1/5 Meno di un'ora Idoneità per principianti 95/100
I maintainer di solito rispondono entro 1 giorno
-
Difficoltà 2/5 1-3 ore Idoneità per principianti 88/100
NousResearch/hermes-agent#140958 ·
I maintainer di solito rispondono entro 1 giorno
-
Bug triage/confirmed
Difficoltà 2/5 Mezza giornata Idoneità per principianti 85/100
agentscope-ai/agentscope#3355 ·
I maintainer di solito rispondono entro 2 giorni