Skip to content

New REPL on Windows exits when accented character is pasted/typed #131878

Description

@devdanzin

Crash report

What happened?

When pasting an accented character like ñ or é, or typing one such as ´p and pressing Enter, then up arrow, the new REPL on Windows will exit with the following error:

Python 3.14.0a6+ (heads/fix_non_string_candidates_exit_repl-dirty:8008a588342, Mar 29 2025, 08:15:) [MSC v.1943 64 bit (AMD64)] on win32
Type "help", "copyright", "credits" or "license" for more information.
>>> Traceback (most recent call last):
  File "<frozen runpy>", line 198, in _run_module_as_main
  File "<frozen runpy>", line 88, in _run_code
  File "C:\Users\ddini\PycharmProjects\cpython\Lib\_pyrepl\__main__.py", line 6, in <module>
    __pyrepl_interactive_console()
    ~~~~~~~~~~~~~~~~~~~~~~~~~~~~^^
  File "C:\Users\ddini\PycharmProjects\cpython\Lib\_pyrepl\main.py", line 59, in interactive_console
    run_multiline_interactive_console(console)
    ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~^^^^^^^^^
  File "C:\Users\ddini\PycharmProjects\cpython\Lib\_pyrepl\simple_interact.py", line 137, in run_multiline_interactive_console
    statement = multiline_input(more_lines, ps1, ps2)
  File "C:\Users\ddini\PycharmProjects\cpython\Lib\_pyrepl\readline.py", line 389, in multiline_input
    return reader.readline()
           ~~~~~~~~~~~~~~~^^
  File "C:\Users\ddini\PycharmProjects\cpython\Lib\_pyrepl\reader.py", line 750, in readline
    self.handle1()
    ~~~~~~~~~~~~^^
  File "C:\Users\ddini\PycharmProjects\cpython\Lib\_pyrepl\reader.py", line 706, in handle1
    event = self.console.get_event(block=False)
  File "C:\Users\ddini\PycharmProjects\cpython\Lib\_pyrepl\windows_console.py", line 471, in get_event
    self.event_queue.push(rec.Event.KeyEvent.uChar.UnicodeChar)
    ~~~~~~~~~~~~~~~~~~~~~^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "C:\Users\ddini\PycharmProjects\cpython\Lib\_pyrepl\base_eventqueue.py", line 88, in push
    assert len(self.buf) == 1
           ^^^^^^^^^^^^^^^^^^
AssertionError

In these cases, len(self.buf) is 3 instead of 1.

I'm running Python in Windows Terminal, chcp gives 850, changing it to 65001 (UTF-8) makes no difference.

CPython versions tested on:

CPython main branch

Operating systems tested on:

Windows

Output from running 'python -VV' on the command line:

Python 3.14.0a6+ (heads/main-dirty:7c3692fe275, Mar 24 2025, 19:20:37) [MSC v.1942 64 bit (AMD64)]

Linked PRs

Activity

  1. added
    type-crashA hard crash of the interpreter, possibly with a core dump
    on Mar 29, 2025
  2. StanFromIreland commented on Mar 29, 2025

    @StanFromIreland
    Member

    Related? #130273

    This is a bug and not a crash.

  3. devdanzin commented on Mar 29, 2025

    @devdanzin
    MemberAuthor

    This is a bug and not a crash.

    Correct, sorry about that.

    cc @DinoV, @y5c4l3, @encukou

  4. added
    type-bugAn unexpected behavior, bug, or error
    topic-replRelated to the interactive shell
    and removed
    type-crashA hard crash of the interpreter, possibly with a core dump
    on Mar 29, 2025
  5. added
    stdlibStandard Library Python modules in the Lib/ directory
    on Mar 29, 2025
  6. StanFromIreland commented on Mar 29, 2025

    @StanFromIreland
    Member

    This is os-windows specific. IIRC there was recently an issue about this, it was closed.

  7. StanFromIreland commented on Mar 29, 2025

    @StanFromIreland
    Member

    Yes looking at #130804 it seems it was not fully resolved, and it is presumably a side effect of the merged pr, do we want to reopen that?

  8. sergey-miryanov commented on Mar 29, 2025

    @sergey-miryanov
    Contributor

    @StanFromIreland
    It is in another execution path, so I think this should be a new issue (despite it looks similar).

  9. StanFromIreland commented on Mar 29, 2025

    @StanFromIreland
    Member

    @sergey-miryanov

    def push(self, char: int | bytes | str) -> None:
    """
    Processes a character by updating the buffer and handling special key mappings.
    """
    ord_char = char if isinstance(char, int) else ord(char)
    if ord_char > 255:
    assert isinstance(char, str)
    char = bytes(char.encode(self.encoding, "replace"))
    self.buf.extend(char)
    else:
    char = bytes(bytearray((ord_char,)))
    self.buf.append(ord_char)
    if char in self.keymap:
    if self.keymap is self.compiled_keymap:
    # sanity check, buffer is empty when a special key comes
    assert len(self.buf) == 1
    k = self.keymap[char]

    It is in the same path you modified, your changes are the last ones to modify the buffer before the check?

  10. added
    3.13only security fixes
    3.14bugs and security fixes
    on Mar 29, 2025
  11. sergey-miryanov commented on Mar 29, 2025

    @sergey-miryanov
    Contributor

    @StanFromIreland Oh, I get what you mean. Yes, it is related, but I think it is related to keymap and compiled_keymap also, so it extends my previous patch a bit. I will test and fix. Can you assign it to me?

  12. sergey-miryanov commented on Mar 29, 2025

    @sergey-miryanov
    Contributor

    Also, I should mention that it is not backported to 3.13 due conflicts - #130805 (comment)

  13. 4 remaining items

  14. added a commit that references this issue on Apr 26, 2025
  15. added 4 commits that reference this issue on May 5, 2025
  16. ambv commented on May 5, 2025

    @ambv
    Contributor

    Fixed, thank you all!

  17. added 2 commits that reference this issue on May 5, 2025
  18. added 2 commits that reference this issue on Jul 12, 2025
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

    3.13only security fixes3.14bugs and security fixesOS-windowsrelease-blockerstdlibStandard Library Python modules in the Lib/ directorytopic-replRelated to the interactive shelltype-bugAn unexpected behavior, bug, or error

    Projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions