Skip to content

Copying emoji causes error in Python 3.14 REPL #155788

Description

@aiwonderland

Bug report

Bug description:

Copying an emoji triggers an error in the new REPL interactive console environment of Python 3.14.

log:

PS C:\Users\***> python
Python 3.14.6 (tags/v3.14.6:c63aec6, Jun 10 2026, 10:26:10) [MSC v.1944 64 bit (AMD64)] on win32
Type "help", "copyright", "credits" or "license" for more information.
>>> "Traceback (most recent call last):
  File "C:\Users\***\AppData\Local\Python\pythoncore-3.14-64\Lib\_pyrepl\readline.py", line 395, in multiline_input
    return reader.readline()
           ~~~~~~~~~~~~~~~^^
  File "C:\Users\***\AppData\Local\Python\pythoncore-3.14-64\Lib\_pyrepl\reader.py", line 759, in readline
    self.handle1()
    ~~~~~~~~~~~~^^
  File "C:\Users\***\AppData\Local\Python\pythoncore-3.14-64\Lib\_pyrepl\reader.py", line 742, in handle1
    self.do_cmd(cmd)
    ~~~~~~~~~~~^^^^^
  File "C:\Users\***\AppData\Local\Python\pythoncore-3.14-64\Lib\_pyrepl\reader.py", line 672, in do_cmd
    self.refresh()
    ~~~~~~~~~~~~^^
  File "C:\Users\******\AppData\Local\Python\pythoncore-3.14-64\Lib\_pyrepl\reader.py", line 649, in refresh
    self.screen = self.calc_screen()
                  ~~~~~~~~~~~~~~~~^^
  File "C:\Users\***\AppData\Local\Python\pythoncore-3.14-64\Lib\_pyrepl\completing_reader.py", line 261, in calc_screen
    screen = super().calc_screen()
  File "C:\Users\***\AppData\Local\Python\pythoncore-3.14-64\Lib\_pyrepl\reader.py", line 315, in calc_screen
    colors = list(gen_colors(self.get_unicode()))
  File "C:\Users\***\AppData\Local\Python\pythoncore-3.14-64\Lib\_pyrepl\utils.py", line 115, in gen_colors
    for color in gen_colors_from_token_stream(gen, line_lengths):
                 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~^^^^^^^^^^^^^^^^^^^
  File "C:\Users\***\AppData\Local\Python\pythoncore-3.14-64\Lib\_pyrepl\utils.py", line 175, in gen_colors_from_token_stream
    for prev_token, token, next_token in token_window:
                                         ^^^^^^^^^^^^
  File "C:\Users\***\AppData\Local\Python\pythoncore-3.14-64\Lib\_pyrepl\utils.py", line 382, in prev_next_window
    window = deque((None, next(iterator)), maxlen=3)
                          ~~~~^^^^^^^^^^
  File "C:\Users\***\AppData\Local\Python\pythoncore-3.14-64\Lib\tokenize.py", line 588, in _generate_tokens_from_c_tokenizer
    for info in it:
                ^^
UnicodeEncodeError: 'utf-8' codec can't encode characters in position 1-2: surrogates not allowed
>>>

CPython versions tested on:

3.14

Operating systems tested on:

Windows

Metadata

Metadata

Assignees

No one assigned

    Labels

    stdlibStandard Library Python modules in the Lib/ directorytopic-replRelated to the interactive shelltype-bugAn unexpected behavior, bug, or error

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions