Skip to content

gh-159672: Generate keyword typo hints in the parser - #159673

Open
pablogsal wants to merge 13 commits into
python:mainfrom
pablogsal:keyword-typo-token-replay
Open

pablogsal wants to merge 13 commits into
python:mainfrom
pablogsal:keyword-typo-token-replay

Conversation

@pablogsal

@pablogsal pablogsal commented Oct 18, 2026 •

Copy link
Copy Markdown
Member

Move keyword typo hints into the parser and attach the result to SyntaxError. Replay private token copies through the grammar, with one replacement per trial. Release trial tokens and identifiers with their arena. Remove source recompilation and statement-location metadata from traceback.

Search the complete logical statement and count adjacent letter swaps as one edit. Preserve comma diagnostics and support typos that spell another keyword.

Use a hint only while the public error fields match their saved values. Block Python callbacks during trial literal conversion and reuse available source text. Keep codeop.compile_command(..., flags=...) compatible.

Limit the search to 256 KiB, 32,768 tokens, 32 candidates, and 5 million rule entries across all trials. Keep the normal parser's fast stack check.

Fixes #159672.

@pablogsal pablogsal added type-feature A feature request or enhancement interpreter-core (Objects, Python, Grammar, and Parser dirs) labels Oct 18, 2026
@pablogsal
pablogsal force-pushed the keyword-typo-token-replay branch 3 times, most recently from a39cdf2 to 05fb3a1 Compare October 18, 2026 14:58
@johnslavik
johnslavik self-requested a review October 20, 2026 16:54
@pablogsal
pablogsal force-pushed the keyword-typo-token-replay branch from cadefcb to 2497054 Compare October 20, 2026 18:30
@pablogsal
pablogsal marked this pull request as ready for review October 21, 2026 01:43
@pablogsal

pablogsal commented Oct 22, 2026 •

Copy link
Copy Markdown
Member Author

(About half of this diff is generated parser code)

@pablogsal
pablogsal force-pushed the keyword-typo-token-replay branch from d12632c to 2d7b753 Compare October 22, 2026 20:44
Use a named alias type with constant pointer fields so the alias table is explicitly immutable.
@pablogsal
pablogsal force-pushed the keyword-typo-token-replay branch from 2d7b753 to cdef8e4 Compare October 23, 2026 04:42
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

awaiting core review interpreter-core (Objects, Python, Grammar, and Parser dirs) type-feature A feature request or enhancement

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Move keyword typo suggestions into the parser

1 participant