Skip to content
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

[3.13] gh-127349: Add check for correct resizing in REPL (GH-127387) #129485

Open
wants to merge 1 commit into
base: 3.13
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 3 additions & 2 deletions Lib/_pyrepl/reader.py
Original file line number Diff line number Diff line change
Expand Up @@ -587,10 +587,11 @@ def setpos_from_xy(self, x: int, y: int) -> None:
def pos2xy(self) -> tuple[int, int]:
"""Return the x, y coordinates of position 'pos'."""
# this *is* incomprehensible, yes.
y = 0
p, y = 0, 0
l2: list[int] = []
pos = self.pos
assert 0 <= pos <= len(self.buffer)
if pos == len(self.buffer):
if pos == len(self.buffer) and len(self.screeninfo) > 0:
y = len(self.screeninfo) - 1
p, l2 = self.screeninfo[y]
return p + sum(l2) + l2.count(0), y
Expand Down
12 changes: 9 additions & 3 deletions Lib/test/test_pyrepl/test_reader.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,9 @@
import functools
import rlcompleter
from unittest import TestCase
from unittest.mock import MagicMock, patch
from unittest.mock import MagicMock

from .support import handle_all_events, handle_events_narrow_console, code_to_events, prepare_reader
from test.support import import_helper
from .support import handle_all_events, handle_events_narrow_console, code_to_events, prepare_reader, prepare_console
from _pyrepl.console import Event
from _pyrepl.reader import Reader

Expand Down Expand Up @@ -313,3 +312,10 @@ def test_key_press_on_tab_press_once(self):
reader, _ = handle_all_events(events, prepare_reader=completing_reader)

self.assert_screen_equals(reader, f"{code}a")

def test_pos2xy_with_no_columns(self):
console = prepare_console([])
reader = prepare_reader(console)
# Simulate a resize to 0 columns
reader.screeninfo = []
self.assertEqual(reader.pos2xy(), (0, 0))
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
Fixed the error when resizing terminal in Python REPL. Patch by Semyon
Moroz.
Loading