Skip to content

gh-162296: Preserve TracebackException lineno types after keyword typo formatting - #162328

Open
Sudhakar7J wants to merge 1 commit into
python:mainfrom
Sudhakar7J:fix/gh-162296-traceback-lineno
Open

Sudhakar7J wants to merge 1 commit into
python:mainfrom
Sudhakar7J:fix/gh-162296-traceback-lineno

Conversation

@Sudhakar7J

Copy link
Copy Markdown

Summary

TracebackException._find_keyword_typos() replaced lineno/end_lineno with tokenizer integer positions when a keyword typo suggestion was applied during formatting, mutating attributes that are initialized as strings for SyntaxError tracebacks. This keeps them as strings (str(start[0]) / str(end[0])) so their type remains stable before and after formatting.

Issue

Fixes gh-162296.

Tests

  • Added test_syntax_error_keyword_typo_preserves_lineno_type in Lib/test/test_traceback.py.
  • Added NEWS entry: Misc/NEWS.d/next/Library/2026-11-20-20-49-33.gh-issue-162296.B5ZoAN.rst.

Verification

  • Reproduced the reported issue on CPython 3.15.2 (Windows): lineno/end_lineno changed from str to int after format() for compile("whille True:\n pass\n", ...).
  • Verified the fix resolves the reproducer by applying the same change to the 3.15.2 traceback implementation in a temporary copy and re-running the case (before/after both str '1').
  • I was unable to run CPython main’s test_traceback in a built main interpreter in this Windows environment (main Lib/traceback.py uses syntax not runnable under 3.15.2 here), so CI/buildbot verification would be appreciated for full suite coverage.

@python-cla-bot

Copy link
Copy Markdown

The following commit authors need to sign the Contributor License Agreement:

CLA not signed

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

TracebackException.lineno changes from str to int after format() when a keyword typo suggestion is found

1 participant