Repository navigation
Fix strict tokenizer lexical error propagation - #9935
Draft
youknowone wants to merge 2 commits into
main from
dot/tokenizer-strict-ed04420
Draft
Conversation
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_syntax expectedFailure marker. No new repository tests or changes to canonical assertions.
Verification
- Linux x86_64, Rust 1.100.0, CPython 3.15.2 reference; main
bf68333 baseline.
test_tokenize passes (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
Copy link
Copy Markdown
Contributor
|
Important
Draft PR not reviewed
Draft PRs are not automatically reviewed by default.
To automatically review draft PRs, update your CodeRabbit configuration:
reviews:
auto_review:
drafts: true
- Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts
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
-
|
Copy link
Copy Markdown
Contributor
📦 Library Dependencies
The following Lib/ modules were modified. Here are their dependencies:
[x] lib: cpython/Lib/tokenize.py
[x] test: cpython/Lib/test/test_tokenize.py (TODO: 1)
dependencies:
dependent tests: (181 tests)
- tokenize: test_free_threading test_inspect test_linecache test_peg_generator test_tabnanny test_tokenize test_unparse
- idlelib: test_idle
- importlib._bootstrap_external: test_importlib test_unittest
- modulefinder: test_importlib test_modulefinder
- py_compile: test_cmd_line_script test_compileall test_importlib test_multiprocessing_main_handling test_py_compile test_pydoc test_runpy
- pydoc: test_enum
- zipfile: test_pdb test_pkgutil test_shutil test_zipapp test_zipfile test_zipfile64 test_zipimport test_zipimport_support
- inspect: test_abc test_argparse test_asyncgen test_buffer test_builtin test_clinic test_code test_collections test_coroutines test_curses test_decimal test_free_threading test_functools test_generators test_grammar test_monitoring test_ntpath test_operator test_patma test_posixpath test_profiling test_pyrepl test_signal test_sqlite3 test_support test_traceback test_turtle test_type_annotations test_type_params test_types test_typing test_unittest test_yield_from test_zoneinfo
- ast: test_ast test_codeop test_compile test_compiler_codegen test_dis test_free_threading test_fstring test_future_stmt test_peepholer test_site test_ssl test_type_comments test_ucn
- bdb: test_bdb
- cmd: test_cmd
- dataclasses: test__colorize test_copy test_ctypes test_genericalias test_pprint test_regrtest
- pdb: test_remote_pdb
- pkgutil: test_pyrepl
- rlcompleter: test_pyrepl test_rlcompleter
- trace: test_trace
- traceback: test_asyncio test_code_module test_concurrent_futures test_contextlib test_contextlib_async test_crossinterp test_dictcomps test_exceptions test_http_cookiejar test_importlib test_iter test_listcomps test_pyexpat test_setcomps test_socket test_subprocess test_sys test_threadedtempfile test_threading test_unittest test_with
- xmlrpc.server: test_docxmlrpc test_xmlrpc
- linecache:
- profiling.sampling.dump: test_profiling
- profiling.sampling.stack_collector: test_profiling
- timeit: test_timeit
- tracemalloc: test_tracemalloc
- traceback:
- concurrent.futures.interpreter: test_concurrent_futures
- concurrent.futures.process: test_concurrent_futures
- http.cookiejar: test_urllib2
- logging: test_asyncio test_hashlib test_logging test_urllib2net
- multiprocessing: test_asyncio test_concurrent_futures test_fcntl test_importlib test_memoryview test_multiprocessing_forkserver test_profiling test_re
- socketserver: test_imaplib test_socketserver test_wsgiref
- threading: test__interpchannels test__interpreters test_android test_asyncio test_bytes test_bz2 test_concurrent_futures test_context test_ctypes test_email test_enumerate test_external_inspection test_fork1 test_frame test_free_threading test_ftplib test_gc test_httplib test_httpservers test_importlib test_interpreters test_io test_ioctl test_itertools test_opcache test_os test_pathlib test_poll test_poplib test_profiling test_pyrepl test_queue test_robotparser test_sched test_smtplib test_super test_syslog test_termios test_threading_local test_time test_urllib2_localnet test_weakref test_winreg test_zstd
- tkinter: test_tcl test_tkinter test_ttk test_ttk_textonly
Legend:
[+] path exists in CPython
[x] up-to-date, [ ] outdated
|
Copy link
Copy Markdown
Contributor
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-unspecified
Sign up for free
to join this conversation on GitHub .
Already have an account?
Sign in to comment
Labels
None yet
1 participant