Skip to content

_pyrepl: AssertionError in pos2xy when recalling long multi-line wide-character history #159459

Closed as not planned

Description

@nsyhykui

Bug report

Bug description

On CPython 3.14.6, the default REPL (_pyrepl) crashes with an AssertionError when recalling a long multi-line history entry that contains wide characters (CJK, emoji, etc.).

Trigger: enter a long multi-line string made of wide characters, press Enter, then press Up to recall it.

Half-width / ASCII characters do not trigger this. All full-width characters tested (Chinese, emoji) do.

Minimal reproducer

a = """
文本文本文本文本文本文本文本文本文本文本文本文本文本文本文本文本文本文本文本文本文本文本文本文本文本文本文本文本文本文本文本文本文本文本文本文本文本文本文本文本文本文本文本文本文本文本文本文本文本文本文本文本文本文本文本文本文本文本文本文本文本文本文本文本文本文本文本文本文本文本文本文本文本文本文本文本文本文本文本文本文本文本文本文本文本文本文本文本文本文本文本文本文本文本文本文本文本文本文本文本

文本文本文本文本文本文本文本文本文本文本文本文本文本文本文本文本文本文本文本文本文本文本文本文本文本文本文本文本文本文本文本文本文本文本文本文本文本文本文本文本文本文本文本文本文本文本文本文本文本文本文本文本文本文本文本文本文本文本文本文本文本文本文本文本文本文本文本文本文本文本文本文本文本文本文本文本文本文本文本文本文本文本文本文本文本文本文本文本文本文本文本文本文本文本文本文本文本文本文本文本
"""

After pressing Enter, press the Up arrow to recall the history entry. The REPL crashes.

Traceback

File ".../_pyrepl/readline.py", line 395, in multiline_input
    return reader.readline()
File ".../_pyrepl/reader.py", line 759, in readline
    self.handle1()
File ".../_pyrepl/reader.py", line 742, in handle1
    self.do_cmd(cmd)
File ".../_pyrepl/reader.py", line 674, in do_cmd
    self.update_cursor()
File ".../_pyrepl/reader.py", line 569, in update_cursor
    self.cxy = self.pos2xy()
File ".../_pyrepl/reader.py", line 537, in pos2xy
    assert 0 <= pos <= len(self.buffer)
AssertionError

CPython versions tested on:

3.14

Operating systems tested on:

Linux

Activity

  1. encukou commented on Oct 15, 2026

    @encukou
    Member

    Which terminal are you using?
    (I could not reproduce with Tilix, Gnome Terminal & Konsole.)

  2. added
    stdlibStandard Library Python modules in the Lib/ directory
    pendingThe issue will be closed if no feedback is provided
    on Oct 15, 2026
  3. edvilme commented on Oct 15, 2026

    @edvilme
    Contributor

    Would love to take a look at this. However wasn't able to repro either. What terminal did you test? Also you mention some emojis, can you provide examples?

  4. nsyhykui commented on Oct 15, 2026

    @nsyhykui
    Author
    $ echo $TERM
    xterm-256color
    $ stty size
    49 88
    
  5. nsyhykui commented on Oct 15, 2026

    @nsyhykui
    Author

    Also reproducible in a wide terminal if a single line is long enough (many characters on one line).

  6. edvilme commented on Oct 15, 2026

    @edvilme
    Contributor

    I am curious if you print a on the terminal, does it render correctly?
    My guess would be that this is a weird issue with the terminal emulator not receiving the input correctly

  7. nsyhykui commented on Oct 15, 2026

    @nsyhykui
    Author

    Yes, print(a) works fine.

  8. nsyhykui commented on Oct 16, 2026

    @nsyhykui
    Author

    I built CPython 3.16 from main and cannot reproduce this anymore. The bug seems to be fixed on main, but still present in 3.14.6 and 3.13.5.

  9. encukou commented on Oct 16, 2026

    @encukou
    Member

    I cannot reproduce on those versions either :(

  10. nsyhykui commented on Oct 16, 2026

    @nsyhykui
    Author

    Two details that seem to be required to reproduce this:

    1. Terminal width: 49 columns (stty size → 49 88). With a wider terminal, the wide-character lines wrap less and the crash doesn't happen.
    2. Press Up twice. The first Up recalls the history entry; the second Up moves the cursor and triggers the crash. Just recalling once may not be enough.

    Could you try with a 49-column terminal and press Up twice?

  11. nsyhykui commented on Oct 16, 2026

    @nsyhykui
    Author

    Maybe try this:

    xterm -geometry 20x10
  12. removed
    pendingThe issue will be closed if no feedback is provided
    on Oct 16, 2026
  13. encukou commented on Oct 16, 2026

    @encukou
    Member

    Ah, that did it. Thank you!

    Bisection shows this was fixed in 3.15 by #146584... which is unfortunately a big refactoring :(

  14. nsyhykui commented on Oct 17, 2026

    @nsyhykui
    Author

    Thanks for the bisect! I'll just wait for 3.15 then.

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

    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