Fix strict tokenizer lexical error propagation by youknowone · Pull Request #9935 · RustPython/RustPython
Repository navigation
Fix strict tokenizer lexical error propagation - #9935
Draft
youknowone wants to merge 2 commits into main from dot/tokenizer-strict-ed04420
Draft
Fix strict tokenizer lexical error propagation #9935 youknowone wants to merge 2 commits into main from dot/tokenizer-strict-ed04420
Conversation
youknowone commented Nov 18, 2026 · edited Loading
Copy link Copy Markdown
Member
Summary
- Propagate lexical tokenizer errors without treating parser grammar recovery as a lexical failure.
- Preserve extra-token tolerance, diagnostic arguments/positions, and token/error ordering for malformed numbers, brackets, strings, interpolations, and NUL input.
- Remove the existing
test_invalid_syntaxexpectedFailure marker. No new repository tests or changes to canonical assertions.
Verification
- Linux x86_64, Rust 1.100.0, CPython 3.15.2 reference; main
bf68333baseline. test_tokenizepasses (132 tests run).- 85 private differential inputs in both modes: all 170 complete records match, including token tuples and exception class/arguments/text/start/end positions.
- Workspace all-targets Clippy passes, excluding wasm, venvlauncher, and CAPI. Mandatory commit hooks pass; prettier skipped because no applicable files.
- Full non-CAPI Rust workspace tests and doctests pass: 1,619 passed, 21 ignored, 0 failed . The ignored cases are two existing process-isolation tests and 19 doctests. CAPI remains deferred per the maintainer's instruction; Windows/WASI and CI are not yet verified.
- Quiet alternating baseline/candidate debug microbenchmarks over four rounds showed median changes of −3.4% for many-line source, −4.6% for long-line source, and −8.1% for f-strings. These local regression checks are not release-performance guarantees.
Remaining limits
This is not complete tokenizer parity. Ruff splits invalid Unicode identifiers such as a€b, so strict mode may emit the valid prefix before the correct diagnostic, and extra-token boundaries differ. A private lexer workaround is deliberately not added. A continuation ending in bare CR still has an EOF line/offset difference; LF/CRLF probes match. Existing eager readline/callback ordering and numeric-keyword SyntaxWarning/filter behavior remain outside this change.
AI assistance
Implementation, differential probes, and independent review used OpenAI Codex. The runtime does not expose an exact model version, so the commit records Assisted-by: Codex:model-unspecified rather than inventing one.
Fix strict tokenizer lexical diagnostics
fdd327a
Propagate lexical errors without treating parser recovery as tokenizer failure. Preserve extra-token tolerance and CPython diagnostic positions and token ordering. Remove the passing canonical invalid-syntax expectedFailure marker. Implementation and differential validation were AI-assisted. Assisted-by: Codex:model-unspecified
coderabbitai
Bot
commented
Nov 18, 2026
Copy link Copy Markdown
Contributor
|
Important Draft PR not reviewedDraft PRs are not automatically reviewed by default.
To automatically review draft PRs, update your CodeRabbit configuration: reviews:
auto_review:
drafts: true
Thanks for using CodeRabbit ! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Share |
github-actions
Bot
commented
Nov 18, 2026
Copy link Copy Markdown
Contributor
📦 Library DependenciesThe following Lib/ modules were modified. Here are their dependencies: [x] lib: cpython/Lib/tokenize.py dependencies:
dependent tests: (181 tests)
Legend:
|
codspeed
Bot
commented
Nov 18, 2026
·
edited
Loading
Copy link Copy Markdown
Contributor
Merging this PR will not alter performance
Comparing Footnotes
|
Ignore parser-recovery brace errors during tokenization
26ae61c
Keep genuine nested f/t-string brace errors while allowing pdb convenience variables through extra-token mode. Reuse bracket tracking rather than suppressing lexical errors globally. Assisted-by: Codex:model-unspecifiedSign up for free to join this conversation on GitHub . Already have an account? Sign in to comment