TracebackException.lineno changes from str to int after format() when a keyword typo suggestion is found
I maintainer di solito rispondono entro 1 giorno
Valutazione
- Difficoltà
- 2/5
- Tempo stimato
- 1-3 ore
- Idoneità per principianti
- 67/100
Direzione di ricerca
Inizia da TracebackException._find_keyword_typos() e controlla come assegna lineno e end_lineno; l’issue indica che la conversione in stringa del costruttore è il comportamento atteso. Leggi i test di traceback per i suggerimenti in caso di errori di battitura nelle parole chiave e aggiungi verifiche per i tipi degli attributi prima e dopo la formattazione. Il lavoro è completato quando la formattazione conserva i tipi documentati o consolidati e il test di regressione ha esito positivo.
Scritto dal modello di indicizzazione a partire dal testo della issue.
Descrizione
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
- Lingua principale
- Python
- Stelle
- 78.4k
- Fork
- 36.6k
- Merge medio
- 23h 34m
- PR unite (30g)
- 610
Preparare l'ambiente
Avvia il container di sviluppo del progetto nel browser, con il tuo account GitHub.
- Nessun Dockerfile né file Docker Compose
- Ha un modello di pull request
- Leggi la guida per i contributori
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 python/cpython
-
interpreter-core type-bug
Difficoltà 2/5 1-3 ore Idoneità per principianti 62/100
I maintainer di solito rispondono entro 1 giorno
-
stdlib topic-subprocess type-bug
Difficoltà 2/5 1-3 ore Idoneità per principianti 72/100
I maintainer di solito rispondono entro 1 giorno
-
corner case: base64.b32decode ignorechars=b'=' miscounts paddingForse già presa @ElDShell l’ha presa oggi. Aperta3.15 easy type-bug
Difficoltà 2/5 1-3 ore Idoneità per principianti 62/100
python/cpython#162353 · 1 commento ·
I maintainer di solito rispondono entro 1 giorno
-
[HACL] The `HACL_CAN_COMPILE_VEC128` macro is not defined when building Python with `-Wundef`Forse già presa @tamaki0575-cloud l’ha presa 1 giorno fa. Apertabuild extension-modules topic-C-API type-bug
Difficoltà 2/5 1-3 ore Idoneità per principianti 64/100
python/cpython#162219 · 2 commenti ·
I maintainer di solito rispondono entro 1 giorno
-
zipfile: ZipInfo.comment exceeding 65535 bytes causes struct.error in ZipFile.close() without proper validationForse già presa @1cbyc l’ha presa 5 giorni fa. Apertastdlib type-bug
Difficoltà 2/5 1-3 ore Idoneità per principianti 75/100
I maintainer di solito rispondono entro 1 giorno
Tutte le issue di python/cpython
Issue simili
-
Difficoltà 2/5 1-3 ore Idoneità per principianti 68/100
vllm-project/vllm#69304 · 1 commento ·
I maintainer di solito rispondono entro 1 giorno
-
pydanty:is-working
Difficoltà 2/5 1-3 ore Idoneità per principianti 68/100
pydantic/pydantic-ai#14187 ·
I maintainer di solito rispondono entro 1 giorno
-
bug
Difficoltà 2/5 1-3 ore Idoneità per principianti 62/100
I maintainer di solito rispondono entro 1 giorno
-
test
Difficoltà 2/5 1-3 ore Idoneità per principianti 62/100
prebid/salesagent#2676 ·
I maintainer di solito rispondono entro 1 giorno
-
Difficoltà 1/5 1-3 ore Idoneità per principianti 62/100
sunososobro-hub/cloudball#339 ·
I maintainer di solito rispondono entro 1 giorno