Bug description
TracebackException.format_exception_only() is not idempotent when _find_keyword_typos() finds a suggestion. The method directly mutates self.text, self.offset, self.end_offset, self.lineno, self.end_lineno, and self.msg, so a second call produces different output (e.g. wrong line number).
import traceback
code = "fr x in range(10):\n pass\n"
try:
compile(code, "<test>", "exec")
except SyntaxError as exc:
te = traceback.TracebackException(type(exc), exc, None)
r1 = list(te.format_exception_only()) # correct
r2 = list(te.format_exception_only()) # different output
assert r1 == r2 # fails
_find_keyword_typos was added in gh-132449.
CPython versions tested on
main
Operating systems tested on
macOS
Linked PRs
Bug description
TracebackException.format_exception_only()is not idempotent when_find_keyword_typos()finds a suggestion. The method directly mutatesself.text,self.offset,self.end_offset,self.lineno,self.end_lineno, andself.msg, so a second call produces different output (e.g. wrong line number)._find_keyword_typoswas added in gh-132449.CPython versions tested on
main
Operating systems tested on
macOS
Linked PRs