def _lex_python_result(result: str) -> Generator[tuple[str, str], None, None]:
    "Return token list for Python string."
    lexer = PythonLexer()
    # Use `get_tokens_unprocessed`, so that we get exactly the same string,
    # without line endings appended. `print_formatted_text` already appends a
    # line ending, and otherwise we'll have two line endings.
    tokens = lexer.get_tokens_unprocessed(result)

    for index, tokentype, text in tokens:
        yield ("class:" + pygments_token_to_classname(tokentype), text)
Return token list for Python string.
src/ptpython/printer.py