Add tests for the C tokenizer and expose it as a private module (GH-27924)

This commit is contained in:
Pablo Galindo Salgado 2021-08-24 17:50:05 +01:00 committed by GitHub
parent 9ed523159c
commit a24676bedc
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
9 changed files with 1114 additions and 5 deletions

View file

@ -680,5 +680,13 @@ def main():
perror("unexpected error: %s" % err)
raise
def _generate_tokens_from_c_tokenizer(source):
"""Tokenize a source reading Python code as unicode strings using the internal C tokenizer"""
import _tokenize as c_tokenizer
for info in c_tokenizer.TokenizerIter(source):
tok, type, lineno, end_lineno, col_off, end_col_off, line = info
yield TokenInfo(type, tok, (lineno, col_off), (end_lineno, end_col_off), line)
if __name__ == "__main__":
main()