TracebackException.lineno changes from str to int after format() when a keyword typo suggestion is found
Los mantenedores suelen responder en 1 día
Evaluación
- Dificultad
- 2/5
- Tiempo estimado
- 1-3 horas
- Aptitud para principiantes
- 67/100
Línea de trabajo
Empieza con TracebackException._find_keyword_typos() e inspecciona cómo asigna lineno y end_lineno; el issue indica que la conversión a cadena del constructor es el comportamiento esperado. Lee las pruebas de traceback para las sugerencias ante errores tipográficos en palabras clave y añade cobertura para los tipos de los atributos antes y después del formateo. El trabajo estará terminado cuando el formateo conserve los tipos documentados o establecidos y pase la prueba de regresión.
Escrito por el modelo de indexación a partir del texto del issue.
Descripción
Bug report
For a SyntaxError, TracebackException stores lineno and end_lineno as strings. When the keyword typo suggestion ("Did you mean 'while'?") triggers during formatting, both attributes are replaced with ints.
import sys
import traceback
print(sys.version)
try:
compile("whille True:\n pass\n", "example.py", "exec")
except SyntaxError as exc:
te = traceback.TracebackException.from_exception(exc)
print("before format():", repr(te.lineno), repr(te.end_lineno))
"".join(te.format())
print("after format(): ", repr(te.lineno), repr(te.end_lineno))
On main:
3.16.0a2+dev (remotes/origin/HEAD:d456158, Nov 19 2026, 22:08:35) [GCC 13.3.0]
before format(): '1' '1'
after format(): 1 1
On 3.14:
3.14.6 (main, Jul 18 2026, 17:01:31) [Clang 22.1.3 ]
before format(): '1' '1'
after format(): 1 1
On 3.13.18 both stay '1', since there are no keyword suggestions there.
The constructor does self.lineno = str(lno), but TracebackException._find_keyword_typos() later assigns self.lineno = start[0] and self.end_lineno = end[0], which are ints from the tokenizer.
The printed traceback is fine, so most people won't notice this. It only shows up if your code reads the attributes directly. For example, te.lineno == '1' is True before calling format() and False after.
It also affects equality: two TracebackException objects created from the same exception compare equal, but stop being equal after you format one of them.
I think the two assignments should be wrapped in str() to match the constructor. I'm happy to send a PR with a test if that's the right direction. The docs don't currently state the type of these attributes, so that could be clarified at the same time.
CPython versions tested on:
CPython main branch
Operating systems tested on:
macOS
- Lenguaje dominante
- Python
- Estrellas
- 78.4k
- Forks
- 36.6k
- Merge medio
- 23 h 34 min
- PR fusionados (30 d)
- 610
Preparar el entorno
Inicia el contenedor de desarrollo del proyecto en tu navegador, con tu propia cuenta de GitHub.
- Sin Dockerfile ni archivo de Docker Compose
- Tiene una plantilla de pull request
- Leer la guía de contribución
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 python/cpython
-
interpreter-core type-bug
Dificultad 2/5 1-3 horas Aptitud para principiantes 62/100
Los mantenedores suelen responder en 1 día
-
stdlib topic-subprocess type-bug
Dificultad 2/5 1-3 horas Aptitud para principiantes 72/100
Los mantenedores suelen responder en 1 día
-
corner case: base64.b32decode ignorechars=b'=' miscounts paddingPosiblemente ocupada @ElDShell la tomó hoy. Abierto3.15 easy type-bug
Dificultad 2/5 1-3 horas Aptitud para principiantes 62/100
python/cpython#162353 · 1 comentario ·
Los mantenedores suelen responder en 1 día
-
[HACL] The `HACL_CAN_COMPILE_VEC128` macro is not defined when building Python with `-Wundef`Posiblemente ocupada @tamaki0575-cloud la tomó hace 1 día. Abiertobuild extension-modules topic-C-API type-bug
Dificultad 2/5 1-3 horas Aptitud para principiantes 64/100
python/cpython#162219 · 2 comentarios ·
Los mantenedores suelen responder en 1 día
-
zipfile: ZipInfo.comment exceeding 65535 bytes causes struct.error in ZipFile.close() without proper validationPosiblemente ocupada @1cbyc la tomó hace 5 días. Abiertostdlib type-bug
Dificultad 2/5 1-3 horas Aptitud para principiantes 75/100
Los mantenedores suelen responder en 1 día
Todos los issues de python/cpython
Issues similares
-
Dificultad 2/5 1-3 horas Aptitud para principiantes 68/100
vllm-project/vllm#69304 · 1 comentario ·
Los mantenedores suelen responder en 1 día
-
pydanty:is-working
Dificultad 2/5 1-3 horas Aptitud para principiantes 68/100
pydantic/pydantic-ai#14187 ·
Los mantenedores suelen responder en 1 día
-
bug
Dificultad 2/5 1-3 horas Aptitud para principiantes 62/100
Los mantenedores suelen responder en 1 día
-
test
Dificultad 2/5 1-3 horas Aptitud para principiantes 62/100
prebid/salesagent#2676 ·
Los mantenedores suelen responder en 1 día
-
Dificultad 1/5 1-3 horas Aptitud para principiantes 62/100
sunososobro-hub/cloudball#339 ·
Los mantenedores suelen responder en 1 día