TracebackException.lineno changes from str to int after format() when a keyword typo suggestion is found
Maintainers usually reply within 1 day
Assessment
- Difficulty
- 2/5
- Estimated time
- 1-3 hours
- Newbie friendliness
- 67/100
Research direction
Start with TracebackException._find_keyword_typos() and inspect how it assigns lineno and end_lineno; the issue names the constructor’s string conversion as the expected behavior. Read the traceback tests for keyword typo suggestions and add coverage for the attribute types before and after formatting. Done means formatting preserves the documented or established types and the regression test passes.
Written by the indexing model from the issue text.
Description
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
- Dominant language
- Python
- Stars
- 78.4k
- Forks
- 36.6k
- Avg merge
- 23h 34m
- Merged PRs (30d)
- 610
Getting set up
Starts the project's dev container in your browser, under your own GitHub account.
- No Dockerfile or Docker Compose file
- Has a pull request template
- Read the contributing guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
More from python/cpython
-
Item assignment and deletion raise `IndexError` instead of `TypeError` on types without them, for a huge indexPossibly taken A pull request linked to this issue is open or already merged. Openinterpreter-core type-bug
Difficulty 2/5 1-3 hours Newbie friendliness 62/100
Maintainers usually reply within 1 day
-
stdlib topic-subprocess type-bug
Difficulty 2/5 1-3 hours Newbie friendliness 72/100
Maintainers usually reply within 1 day
-
corner case: base64.b32decode ignorechars=b'=' miscounts paddingPossibly taken @ElDShell claimed this 1 day ago. Open3.15 easy type-bug
Difficulty 2/5 1-3 hours Newbie friendliness 62/100
python/cpython#162353 · 1 comment ·
Maintainers usually reply within 1 day
-
[HACL] The `HACL_CAN_COMPILE_VEC128` macro is not defined when building Python with `-Wundef`Possibly taken @tamaki0575-cloud claimed this 1 day ago. Openbuild extension-modules topic-C-API type-bug
Difficulty 2/5 1-3 hours Newbie friendliness 64/100
python/cpython#162219 · 2 comments ·
Maintainers usually reply within 1 day
-
zipfile: ZipInfo.comment exceeding 65535 bytes causes struct.error in ZipFile.close() without proper validationPossibly taken @1cbyc claimed this 6 days ago. Openstdlib type-bug
Difficulty 2/5 1-3 hours Newbie friendliness 75/100
Maintainers usually reply within 1 day
Similar issues
-
bot-triaged module: correctness (silent) module: fft triage review
Difficulty 2/5 1-3 hours Newbie friendliness 75/100
Maintainers usually reply within 1 day
-
Difficulty 1/5 Under an hour Newbie friendliness 78/100
conda-forge/zarpaint-feedstock#8 · 1 comment · 1 reaction ·
-
plot_prediction colorbar shows a 0-1 range instead of the data rangePossibly taken @nikhil3495 claimed this today. Open
Difficulty 2/5 1-3 hours Newbie friendliness 68/100
mllam/neural-lam#902 ·
Maintainers usually reply within 2 days
-
Difficulty 2/5 1-3 hours Newbie friendliness 62/100
didi/helixharness#28 ·
Maintainers usually reply within 1 day
-
enhancement
Difficulty 1/5 Under an hour Newbie friendliness 62/100
DaoCloud/DaoCloud-docs#7839 ·
Maintainers usually reply within 1 day