https://github.com/python/cpython/commit/08b045c438a18e59c33b512edc72ace3aba752c3
commit: 08b045c438a18e59c33b512edc72ace3aba752c3
branch: 3.13
author: donBarbos <[email protected]>
committer: ambv <[email protected]>
date: 2025-02-04T15:18:22+01:00
summary:
[3.13] gh-127349: Add check for correct resizing in REPL (GH-127387) (#129485)
(cherry picked from commit 510fefdc625dd2ed2b6b3975314a59e291b94ae8)
files:
A
Misc/NEWS.d/next/Core_and_Builtins/2024-11-30-16-13-31.gh-issue-127349.ssYd6n.rst
M Lib/_pyrepl/reader.py
M Lib/test/test_pyrepl/test_reader.py
diff --git a/Lib/_pyrepl/reader.py b/Lib/_pyrepl/reader.py
index 935c520c5ad553..dc26bfd3a34ffb 100644
--- a/Lib/_pyrepl/reader.py
+++ b/Lib/_pyrepl/reader.py
@@ -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
diff --git a/Lib/test/test_pyrepl/test_reader.py
b/Lib/test/test_pyrepl/test_reader.py
index 8c5efd003de5e8..27c6d6664eda9e 100644
--- a/Lib/test/test_pyrepl/test_reader.py
+++ b/Lib/test/test_pyrepl/test_reader.py
@@ -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
@@ -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))
diff --git
a/Misc/NEWS.d/next/Core_and_Builtins/2024-11-30-16-13-31.gh-issue-127349.ssYd6n.rst
b/Misc/NEWS.d/next/Core_and_Builtins/2024-11-30-16-13-31.gh-issue-127349.ssYd6n.rst
new file mode 100644
index 00000000000000..3c1586b6cbb8e7
--- /dev/null
+++
b/Misc/NEWS.d/next/Core_and_Builtins/2024-11-30-16-13-31.gh-issue-127349.ssYd6n.rst
@@ -0,0 +1,2 @@
+Fixed the error when resizing terminal in Python REPL. Patch by Semyon
+Moroz.
_______________________________________________
Python-checkins mailing list -- [email protected]
To unsubscribe send an email to [email protected]
https://mail.python.org/mailman3/lists/python-checkins.python.org/
Member address: [email protected]