]> git.ipfire.org Git - thirdparty/Python/cpython.git/commitdiff
gh-146458: Fix REPL height and width tracking on resize (#146459)
authorGabriel Volles Marinho <147559808+GabrielvMarinho@users.noreply.github.com>
Tue, 7 Apr 2026 21:09:11 +0000 (18:09 -0300)
committerGitHub <noreply@github.com>
Tue, 7 Apr 2026 21:09:11 +0000 (23:09 +0200)
Co-authored-by: blurb-it[bot] <43283697+blurb-it[bot]@users.noreply.github.com>
Co-authored-by: Victor Stinner <vstinner@python.org>
Lib/_pyrepl/reader.py
Lib/_pyrepl/unix_console.py
Lib/test/test_pyrepl/support.py
Lib/test/test_pyrepl/test_reader.py
Lib/test/test_pyrepl/test_unix_console.py
Lib/test/test_pyrepl/test_windows_console.py
Misc/NEWS.d/next/Windows/2026-03-27-22-06-10.gh-issue-146458.fYj0UQ.rst [new file with mode: 0644]

index f35a99fb06a3f9ebe5bb8a035727fa6495c5751f..6f30986f8be0b1c8e5c5d8abeb25258bab2b11ae 100644 (file)
@@ -651,6 +651,7 @@ class Reader:
 
     def refresh(self) -> None:
         """Recalculate and refresh the screen."""
+        self.console.height, self.console.width = self.console.getheightwidth()
         # this call sets up self.cxy, so call it first.
         self.screen = self.calc_screen()
         self.console.refresh(self.screen, self.cxy)
index 937b5df6ff7d4c37fe4244d54effedb3542e8306..639d16db3f88d4199e3f75e764091d18a77c2691 100644 (file)
@@ -776,7 +776,6 @@ class UnixConsole(Console):
         self.__write_code(self._cup, y - self.__offset, x)
 
     def __sigwinch(self, signum, frame):
-        self.height, self.width = self.getheightwidth()
         self.event_queue.insert(Event("resize", None))
 
     def __hide_cursor(self):
index 4f7f9d77933336f22060c78da060f02910115014..307bf4505550d61f8647b3f75f2a2a0b2552e92b 100644 (file)
@@ -88,6 +88,8 @@ def prepare_console(events: Iterable[Event], **kwargs) -> MagicMock | Console:
     console.get_event.side_effect = events
     console.height = 100
     console.width = 80
+    console.getheightwidth = MagicMock(side_effect=lambda: (console.height, console.width))
+
     for key, val in kwargs.items():
         setattr(console, key, val)
     return console
index b1b6ae16a1e592cac2487e4e89539551a940e101..fbf557115f8a254d2b062a35d0cfa60e6527af1b 100644 (file)
@@ -228,6 +228,7 @@ class TestReader(ScreenEqualMixin, TestCase):
             console.get_event.side_effect = events
             console.height = 100
             console.width = 80
+            console.getheightwidth = MagicMock(side_effect=lambda: (console.height, console.width))
             console.input_hook = input_hook
             return console
 
index a1ee6d4878fe93bfd325636ac5ddf739f05a9e14..8198d489188f1e128771d6e1b09fec1e21da5e93 100644 (file)
@@ -250,8 +250,7 @@ class TestConsole(TestCase):
         events = itertools.chain(code_to_events(code))
         reader, console = handle_events_short_unix_console(events)
 
-        console.height = 2
-        console.getheightwidth = MagicMock(lambda _: (2, 80))
+        console.getheightwidth = MagicMock(side_effect=lambda: (2, 80))
 
         def same_reader(_):
             return reader
@@ -286,8 +285,7 @@ class TestConsole(TestCase):
         events = itertools.chain(code_to_events(code))
         reader, console = handle_events_unix_console_height_3(events)
 
-        console.height = 1
-        console.getheightwidth = MagicMock(lambda _: (1, 80))
+        console.getheightwidth = MagicMock(side_effect=lambda: (1, 80))
 
         def same_reader(_):
             return reader
index f03f84e0985c1f453dab1b80e9349c3a46d0bb90..dbd0e7b071a279ba4c0d3040754d575b5c70565e 100644 (file)
@@ -129,9 +129,7 @@ class WindowsConsoleTests(TestCase):
         events = code_to_events(code)
         reader, console = self.handle_events_narrow(events)
 
-        console.height = 20
-        console.width = 80
-        console.getheightwidth = MagicMock(lambda _: (20, 80))
+        console.getheightwidth = MagicMock(side_effect=lambda: (20, 80))
 
         def same_reader(_):
             return reader
@@ -157,9 +155,7 @@ class WindowsConsoleTests(TestCase):
         events = code_to_events(code)
         reader, console = self.handle_events(events)
 
-        console.height = 20
-        console.width = 4
-        console.getheightwidth = MagicMock(lambda _: (20, 4))
+        console.getheightwidth = MagicMock(side_effect=lambda: (20, 4))
 
         def same_reader(_):
             return reader
@@ -292,8 +288,7 @@ class WindowsConsoleTests(TestCase):
         events = itertools.chain(code_to_events(code))
         reader, console = self.handle_events_short(events)
 
-        console.height = 2
-        console.getheightwidth = MagicMock(lambda _: (2, 80))
+        console.getheightwidth = MagicMock(side_effect=lambda: (2, 80))
 
         def same_reader(_):
             return reader
@@ -330,8 +325,7 @@ class WindowsConsoleTests(TestCase):
         events = itertools.chain(code_to_events(code))
         reader, console = self.handle_events_height_3(events)
 
-        console.height = 1
-        console.getheightwidth = MagicMock(lambda _: (1, 80))
+        console.getheightwidth = MagicMock(side_effect=lambda: (1, 80))
 
         def same_reader(_):
             return reader
diff --git a/Misc/NEWS.d/next/Windows/2026-03-27-22-06-10.gh-issue-146458.fYj0UQ.rst b/Misc/NEWS.d/next/Windows/2026-03-27-22-06-10.gh-issue-146458.fYj0UQ.rst
new file mode 100644 (file)
index 0000000..178c04c
--- /dev/null
@@ -0,0 +1 @@
+Fix incorrect REPL height and width tracking on console window resize on Windows.