ValueError: start precedes previous end, for a backslash line continuation after a reformatted docstring
Nadie ha tomado este issue todavía.
Evaluación
- Dificultad
- 3/5
- Tiempo estimado
- 1-2 días
- Aptitud para principiantes
- 68/100
Línea de trabajo
Comienza con docformatter/format.py, especialmente con _do_format_code y _do_update_token_indices, y luego ejecuta el reproductor t.py proporcionado con --check. Añade o inspecciona la prueba de regresión mencionada en el issue y verifica que las continuaciones con barra invertida después de docstrings reformateados ya no provoquen un tokenizer ValueError en las versiones compatibles de Python.
Escrito por el modelo de indexación a partir del texto del issue.
Descripción
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.
- Lenguaje dominante
- Python
- Estrellas
- 598
- Forks
- 93
- Métricas de merge de PR
- Sin PR fusionados en 30 d
Preparar el entorno
Aún no hemos revisado los archivos de configuración de este proyecto. Empieza por su README y consulta nuestra guía para la primera contribución para los pasos generales.
Primeros pasos
- Lee el issue completo y luego la guía de contribución del proyecto.
- Comenta en el issue que vas a ocuparte — evita que dos personas hagan lo mismo.
- Haz un fork del repositorio y trabaja en una rama.
- Abre un pull request que haga referencia al número del issue.
Más de PyCQA/docformatter
-
fresh
Dificultad 2/5 1-3 horas Aptitud para principiantes 88/100
PyCQA/docformatter#383 ·
-
fresh
Dificultad 3/5 1-2 días Aptitud para principiantes 78/100
PyCQA/docformatter#385 ·
-
fresh
Dificultad 3/5 1-2 días Aptitud para principiantes 72/100
PyCQA/docformatter#379 ·
-
C: convention P: bug U: high
Dificultad 3/5 1-2 días Aptitud para principiantes 74/100
PyCQA/docformatter#367 · 1 comentario ·
-
1.7.8 rewrites the contents of a non-docstring triple-quoted string, silently changing its valueAbiertoC: convention P: bug U: high
Dificultad 3/5 1-2 días Aptitud para principiantes 72/100
PyCQA/docformatter#366 ·
Todos los issues de PyCQA/docformatter
Issues similares
-
bug
Dificultad 2/5 1-3 horas Aptitud para principiantes 85/100
Los mantenedores suelen responder en 1 día
-
Dificultad 1/5 Menos de una hora Aptitud para principiantes 90/100
Los mantenedores suelen responder en 1 día
-
https://search.utilibre.orgAbiertoinstance instance add
Dificultad 2/5 1-3 horas Aptitud para principiantes 68/100
searxng/searx-instances#941 · 1 comentario ·
-
Dificultad 1/5 Menos de una hora Aptitud para principiantes 92/100
FluidNumerics/fluid-walk-blocker#89 ·
Los mantenedores suelen responder en 1 día
-
bug
Dificultad 2/5 1-3 horas Aptitud para principiantes 84/100
Los mantenedores suelen responder en 1 día