Skip to content

PyREPL crashes when there aren't enough columns #127349

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
trag1c opened this issue Nov 27, 2024 · 0 comments
Closed

PyREPL crashes when there aren't enough columns #127349

trag1c opened this issue Nov 27, 2024 · 0 comments
Labels
3.13 bugs and security fixes 3.14 bugs and security fixes stdlib Python modules in the Lib dir topic-repl Related to the interactive shell type-bug An unexpected behavior, bug, or error

Comments

@trag1c
Copy link
Contributor

trag1c commented Nov 27, 2024

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

@trag1c trag1c added the type-bug An unexpected behavior, bug, or error label Nov 27, 2024
@skirpichev skirpichev added the topic-repl Related to the interactive shell label Nov 28, 2024
@picnixz picnixz added stdlib Python modules in the Lib dir 3.13 bugs and security fixes 3.14 bugs and security fixes labels Nov 28, 2024
donBarbos added a commit to donBarbos/cpython that referenced this issue Jan 30, 2025
ambv pushed a commit that referenced this issue Feb 4, 2025
@ambv ambv closed this as completed Feb 6, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
3.13 bugs and security fixes 3.14 bugs and security fixes stdlib Python modules in the Lib dir topic-repl Related to the interactive shell type-bug An unexpected behavior, bug, or error
Projects
None yet
Development

No branches or pull requests

4 participants