Skip to content

Match tokenizer token metadata with CPython 3.15 - #9445

Merged
youknowone merged 2 commits into
RustPython:mainfrom
youknowdot:youknowdot/tokenizer-metadata-315-20261028
Oct 29, 2026
Merged

youknowone merged 2 commits into
RustPython:mainfrom
youknowdot:youknowdot/tokenizer-metadata-315-20261028

Conversation

@youknowdot

@youknowdot youknowdot commented Oct 29, 2026 •

Copy link
Copy Markdown
Contributor

Summary

  • Match CPython 3.15 non-extra INDENT/DEDENT token text and column metadata.
  • Match trailing EOF line text, implicit NL placement for final comments/whitespace, and ordinary STRING physical-line spans.
  • Retire the verified CTokenizeTest.test_async and TestTokenize.test_newline_and_space_at_the_end_of_the_source_without_newline expected-failure markers through actual scripts/update_lib migrate from CPython d220409a13b77de7a6c30abe16ea90db01528edc. The remaining invalid-syntax and resource-dependent random-files markers remain unchanged.

This is a focused native tokenizer plus its dependent Lib test update, separate from the free-threading aggregate and builtin-construction changes. It does not change lexer grammar, callback ownership or the tokenizer's Reading/Yielding synchronization. The free-threading tokenizer module remains outside this patch.

Validation

  • Scoped cargo check and strict Clippy passed; one guarded final executable build passed.
  • Final protected executable SHA256: 64e701982b3bad37b03c0a16b68a485682bed9527ba629db51dfa0425aaaa55a, built from main 8c6c94b07174224517b6bf62abab202565382ea7 plus this native change. All 607 recorded native inputs were verified.
  • Fourteen complete token-tuple comparisons matched pinned CPython exactly, in both extra-token modes across seven bounded inputs: EOF/newlines, nested dedents, trailing comments/whitespace, and an ordinary multiline string.
  • Five complete unchanged canonical methods passed without skips or expected failures: CTokenizeTest.test_async, test_function, test_tabs, test_unicode, and TokenizeTest.test_basic. The additional full canonical newline-space method passed separately. Both complete updater-generated methods then passed together (2 tests, no skips or expected failures).

The follow-up corrects the non-extra INDENT location after an explicit continuation and classifies a complete leading-zero decimal token as NUMBER only in extra-token mode when its exact Ruff diagnostic identifies that token. Both complete canonical methods now pass; their markers were retired through actual update_lib migration.

These finite checks do not establish complete tokenizer or invalid-input parity. No full-module/workspace/CAPI, concurrency, reentry, crash, GC or stress test was run. Existing callback-state ownership and other tokenizer expected failures remain separate work.

AI assistance

OpenAI Codex assisted with implementation, source review, validation and this description.

Follow-up: continuation, leading-zero tokens and UTF-8 EOF line lookup

The original c178 head failed the canonical pyrepl double-width-character test because EOF line lookup used the last byte rather than a UTF-8 character boundary. The follow-up selects the final character's byte offset and shares that lookup between both EOF-line callsites. It does not change Ruff, lexer grammar, callback ownership or the free-threading tokenizer state machine.

Final protected executable SHA-256: 468375918b727a3c74d81772620eba1ca4a25c386c28ad9c3c43b3de15399a5c. Scoped check, strict Clippy and one guarded final build passed; all 607 native inputs were verified. Evidence on this final corrected executable:

  • 23 prior full-tuple comparisons matched pinned CPython exactly: the original 14 and nine additional leading-zero/numeric controls.
  • 14 of 16 new Unicode/empty-input comparisons matched exactly. Both oracle processes exited normally and all cases terminated. Two pre-existing non-extra-mode differences remain: empty input emits an ENDMARKER rather than no token, and CRLF input differs in NEWLINE spelling/end column and ENDMARKER line text. The failed exact comparison is retained; these two cases are not claimed as passes or silently excluded. The UTF-8 lookup change preserves the previous offsets for empty/ASCII LF endings and does not fix these separate metadata gaps.
  • Nine complete canonical tokenizer methods passed, including continuation indentation, leading-zero numbers and the prior regression selections, with no skips or expected failures.
  • One complete canonical pyrepl method passed: TestCursorPosition.test_cursor_position_double_width_character, using its synthetic event and mock console. This verifies the exact previously failing test locally; the full pyrepl module was not run locally.
  • Actual scripts/update_lib migrate from the pinned source retired only the additional continuation-indentation and leading-zero expected-failure decorators. Both complete generated methods passed on the same protected executable, with no skips or expected failures. The remaining two markers are unchanged.

The extra Unicode comparison failure stopped the initial driver before the canonical selections; the already-reviewed canonical methods were then run separately with their own successful receipts. No blanket Unicode/tokenizer parity or new-head CI success is claimed. No concurrency, FT, deep-nesting, random-file, GC, profiler or crash-stress suite was run.

Assisted-by: OpenAI Codex: model version unavailable
@coderabbitai

coderabbitai Bot commented Oct 29, 2026 •

Copy link
Copy Markdown
Contributor

Review in Change Stack →

Caution

Review failed

The pull request is closed.

Finishing Touches
🧪 Generate unit tests (beta)
  • Create a new PR
  • 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

Comment @coderabbitai help to get the list of available commands.

@github-actions

github-actions Bot commented Oct 29, 2026 •

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: 2)

dependencies:

  • tokenize

dependent tests: (175 tests)

  • tokenize: 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_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_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_pathlib test_poll test_poplib 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

Assisted-by: OpenAI Codex: model version unavailable
@youknowone
youknowone marked this pull request as ready for review October 29, 2026 04:34
@youknowone
youknowone merged commit 5f95fd8 into RustPython:main Oct 29, 2026
21 checks passed
@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Oct 29, 2026 •

Copy link
Copy Markdown

Codex Review Summary

This comment shows the latest Codex review activity on this pull request.

Review Status Commit Review trigger
📝 Code Review ⚠️ Failed 2026-10-29T04:40:51.339040Z
We couldn’t complete this review. Comment @codex review to try again.
f8db381 Draft marked ready
ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review" or "@codex security review".

Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants