]> git.ipfire.org Git - thirdparty/Python/cpython.git/commit
gh-142236: Fix incorrect keyword suggestions for syntax errors (#142328)
authorPablo Galindo Salgado <Pablogsal@gmail.com>
Sat, 6 Dec 2025 21:09:35 +0000 (21:09 +0000)
committerGitHub <noreply@github.com>
Sat, 6 Dec 2025 21:09:35 +0000 (21:09 +0000)
commited4f78a4b318e57c9cadad2296c8b977431df6b3
treeab77f18c1684c4e50caa16a2cf33be9582212d76
parent07eff899d8a8ee4c4b1be7cb223fe25687f6216c
gh-142236: Fix incorrect keyword suggestions for syntax errors (#142328)

The keyword typo suggestion mechanism in traceback would incorrectly
suggest replacements when the extracted source code was merely incomplete
rather than containing an actual typo. For example, when a missing comma
caused a syntax error, the system would suggest replacing 'print' with
'not' because the incomplete code snippet happened to pass validation.

The fix adds a validation step that first checks whether the original
extracted code raises a SyntaxError. If the code compiles successfully
or is simply incomplete (compile_command returns None), the function
returns early since there is no way to verify that a keyword replacement
would actually fix the problem.
Lib/test/test_traceback.py
Lib/traceback.py
Misc/NEWS.d/next/Core_and_Builtins/2025-12-06-00-16-43.gh-issue-142236.m3EF9E.rst [new file with mode: 0644]