Skip to content

PyREPL crashes when there aren't enough columns #127349

Closed

Description

@trag1c

Bug report

Bug description:

To reproduce

(order doesn't matter)

  • Open the new REPL
  • Resize the terminal emulator window to be less than 5 cells wide

Traceback

Traceback (most recent call last):
  File "<frozen runpy>", line 198, in _run_module_as_main
  File "<frozen runpy>", line 88, in _run_code
  File "/Users/trag1c/.pyenv/versions/3.13.0/lib/python3.13/_pyrepl/__main__.py", line 6, in <module>
    __pyrepl_interactive_console()
    ~~~~~~~~~~~~~~~~~~~~~~~~~~~~^^
  File "/Users/trag1c/.pyenv/versions/3.13.0/lib/python3.13/_pyrepl/main.py", line 59, in interactive_console
    run_multiline_interactive_console(console)
    ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~^^^^^^^^^
  File "/Users/trag1c/.pyenv/versions/3.13.0/lib/python3.13/_pyrepl/simple_interact.py", line 151, in run_multiline_interactive_console
    statement = multiline_input(more_lines, ps1, ps2)
  File "/Users/trag1c/.pyenv/versions/3.13.0/lib/python3.13/_pyrepl/readline.py", line 389, in multiline_input
    return reader.readline()
           ~~~~~~~~~~~~~~~^^
  File "/Users/trag1c/.pyenv/versions/3.13.0/lib/python3.13/_pyrepl/reader.py", line 801, in readline
    self.handle1()
    ~~~~~~~~~~~~^^
  File "/Users/trag1c/.pyenv/versions/3.13.0/lib/python3.13/_pyrepl/reader.py", line 770, in handle1
    self.refresh()
    ~~~~~~~~~~~~^^
  File "/Users/trag1c/.pyenv/versions/3.13.0/lib/python3.13/_pyrepl/reader.py", line 691, in refresh
    self.screen = self.calc_screen()
                  ~~~~~~~~~~~~~~~~^^
  File "/Users/trag1c/.pyenv/versions/3.13.0/lib/python3.13/_pyrepl/completing_reader.py", line 261, in calc_screen
    screen = super().calc_screen()
  File "/Users/trag1c/.pyenv/versions/3.13.0/lib/python3.13/_pyrepl/reader.py", line 413, in calc_screen
    self.cxy = self.pos2xy()
               ~~~~~~~~~~~^^
  File "/Users/trag1c/.pyenv/versions/3.13.0/lib/python3.13/_pyrepl/reader.py", line 595, in pos2xy
    p, l2 = self.screeninfo[y]
            ~~~~~~~~~~~~~~~^^^
IndexError: list index out of range

The relevant fragment of code

def pos2xy(self) -> tuple[int, int]:
"""Return the x, y coordinates of position 'pos'."""
# this *is* incomprehensible, yes.
y = 0
pos = self.pos
assert 0 <= pos <= len(self.buffer)
if pos == len(self.buffer):
y = len(self.screeninfo) - 1
p, l2 = self.screeninfo[y]
return p + sum(l2) + l2.count(0), y

An additional demo

Screen.Recording.2024-11-27.at.11.47.29.PM.mov

CPython versions tested on:

3.13, 3.14

Operating systems tested on:

Linux, macOS

Linked PRs

Activity

  1. added
    type-bugAn unexpected behavior, bug, or error
    on Nov 27, 2024
  2. added
    stdlibStandard Library Python modules in the Lib/ directory
    3.13only security fixes
    3.14bugs and security fixes
    on Nov 28, 2024
  3. added a commit that references this issue on Jan 30, 2025
  4. added a commit that references this issue on Jan 30, 2025
  5. added a commit that references this issue on Feb 4, 2025
  6. added a commit that references this issue on Feb 7, 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 fixesstdlibStandard 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