]> git.ipfire.org Git - thirdparty/Python/cpython.git/commit
gh-102856: Python tokenizer implementation for PEP 701 (#104323)
authorMarta Gómez Macías <mgmacias@google.com>
Sun, 21 May 2023 00:03:02 +0000 (02:03 +0200)
committerGitHub <noreply@github.com>
Sun, 21 May 2023 00:03:02 +0000 (01:03 +0100)
commit6715f91edcf6f379f666e18f57b8a0dcb724bf79
tree25724d6eb5b8ff5e713f7bfd8f6c33e5a6d87f62
parent3ed57e4995d9f8583083483f397ddc3131720953
gh-102856: Python tokenizer implementation for PEP 701 (#104323)

This commit replaces the Python implementation of the tokenize module with an implementation
that reuses the real C tokenizer via a private extension module. The tokenize module now implements
a compatibility layer that transforms tokens from the C tokenizer into Python tokenize tokens for backward
compatibility.

As the C tokenizer does not emit some tokens that the Python tokenizer provides (such as comments and non-semantic newlines), a new special mode has been added to the C tokenizer mode that currently is only used via
the extension module that exposes it to the Python layer. This new mode forces the C tokenizer to emit these new extra tokens and add the appropriate metadata that is needed to match the old Python implementation.

Co-authored-by: Pablo Galindo <pablogsal@gmail.com>
22 files changed:
Doc/library/token-list.inc
Doc/library/token.rst
Grammar/Tokens
Include/internal/pycore_global_objects_fini_generated.h
Include/internal/pycore_global_strings.h
Include/internal/pycore_runtime_init_generated.h
Include/internal/pycore_token.h
Include/internal/pycore_unicodeobject_generated.h
Lib/inspect.py
Lib/tabnanny.py
Lib/test/test_tabnanny.py
Lib/test/test_tokenize.py
Lib/token.py
Lib/tokenize.py
Misc/NEWS.d/next/Core and Builtins/2023-05-20-23-08-48.gh-issue-102856.Knv9WT.rst [new file with mode: 0644]
Parser/pegen.c
Parser/pegen_errors.c
Parser/token.c
Parser/tokenizer.c
Parser/tokenizer.h
Python/Python-tokenize.c
Python/clinic/Python-tokenize.c.h