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.

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
Skip immortal interning for replay-only identifiers and dotted names.
The parser can then release those strings after each trial.
Separate candidate collection, trial acceptance, and hint construction.
Keep trial allocation and cleanup together, and restore the original
syntax error through one exit path.
A trial can reject a bytes literal without a pending exception. Stop the decode-error path before it requires that exception, and preserve the original syntax error.
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 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)

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