Skip to content

Entering 👪 into the Python 3.15 interactive REPL on Windows throws a UnicodeEncodeError: surrogates not allowed #163132

Backlog

Description

@Eason-Chen13

Bug report

Environment

  • Windows 11 (10.0.26300.9974)
  • Windows Terminal 1.25.3131.0 & Windows Powershell 5.1
  • Windows Terminal 1.25.3131.0 & Windows Powershell 7.6.6
  • conhost.exe & cmd.exe
  • Python 3.15 with Python Install Manager

Steps to reproduce

    1. Enter 'python' to terminal to open Python interactive REPL
    1. Type or paset '👪' into REPL
    1. It throws an error immediately after typing

Actual Behavior

All four terminals behave the same:

Traceback (most recent call last):
  File "...\Lib\_pyrepl\readline.py", line 407, in multiline_input
    return reader.readline()
  File "...\Lib\_pyrepl\reader.py", line 1021, in readline
    self.handle1()
  File "...\Lib\_pyrepl\reader.py", line 1004, in handle1
    self.do_cmd(cmd)
  File "...\Lib\_pyrepl\reader.py", line 932, in do_cmd
    self.update_screen()
  File "...\Lib\_pyrepl\reader.py", line 889, in update_screen
    self.refresh()
  File "...\Lib\_pyrepl\reader.py", line 895, in refresh
    base_screen = self.calc_screen()
  File "...\Lib\_pyrepl\reader.py", line 446, in calc_screen
    content_lines = self._build_content_lines(...)
  File "...\Lib\_pyrepl\reader.py", line 539, in _build_content_lines
    colors = list(self.gen_colors(self.get_unicode()))
  File "...\Lib\_pyrepl\utils.py", line 132, in gen_colors
    for color in gen_colors_from_token_stream(gen, line_lengths):
  File "...\Lib\_pyrepl\utils.py", line 192, in gen_colors_from_token_stream
    for prev_token, token, next_token in token_window:
  File "...\Lib\_pyrepl\utils.py", line 426, in prev_next_window
    first = next(iterator)
  File "...\Lib\tokenize.py", line 634, in _generate_tokens_from_c_tokenizer
    for info in it:
UnicodeEncodeError: 'utf-8' codec can't encode characters in position 0-1: surrogates not allowed

Expected behavior

The terminal shows '👪' or '??' without throwing an error.

Situations with no problems

  • python -c "print(len('👪'))"
  • echo print(len('👪')) | python

Additional information

This issue can also be reproduced on Windows 10 without using WindowsTerminal.exe.

CPython versions tested on:

3.15

Operating systems tested on:

Windows

Activity

  1. added
    type-bug
    on Dec 4, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    type-bug

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions