Skip to content

gh-146458: Fix repl height and width tracking on resize#146459

Merged
vstinner merged 5 commits intopython:mainfrom
GabrielvMarinho:fix-repl-height-and-width-tracking-on-resize
Apr 7, 2026
Merged

gh-146458: Fix repl height and width tracking on resize#146459
vstinner merged 5 commits intopython:mainfrom
GabrielvMarinho:fix-repl-height-and-width-tracking-on-resize

Conversation

@GabrielvMarinho
Copy link
Copy Markdown
Contributor

@GabrielvMarinho GabrielvMarinho commented Mar 26, 2026

On windows, the resize event should be triggering an update in the console height and width, however this is not happening.

I noticed the Unix console didn't have this problem, it was updating fine. My suggestion to fixing this is taking the resizing logic from both console implementations and let it at the reader level, that way it will update both (Unix and windows).

After adding this change, the resizing was happening:

fixed-repl-video.mp4

The tests then started failing as the Magic Mocks to getheightwidth weren't actually returning a tuple with the height and width, so I changed it by adding the side_effect keyword and sending a lambda with the values. With that addition, the tests are actually testing if the resize is happening, if you comment out the height and width resizing logic, they will fail.

@python-cla-bot
Copy link
Copy Markdown

python-cla-bot bot commented Mar 26, 2026

All commit authors signed the Contributor License Agreement.

CLA signed

@bedevere-app
Copy link
Copy Markdown

bedevere-app bot commented Mar 26, 2026

Most changes to Python require a NEWS entry. Add one using the blurb_it web app or the blurb command-line tool.

If this change has little impact on Python users, wait for a maintainer to apply the skip news label instead.

@GabrielvMarinho GabrielvMarinho force-pushed the fix-repl-height-and-width-tracking-on-resize branch from 29dca79 to 47c7453 Compare March 26, 2026 23:19
@bedevere-app
Copy link
Copy Markdown

bedevere-app bot commented Mar 26, 2026

Most changes to Python require a NEWS entry. Add one using the blurb_it web app or the blurb command-line tool.

If this change has little impact on Python users, wait for a maintainer to apply the skip news label instead.

@GabrielvMarinho GabrielvMarinho marked this pull request as ready for review March 27, 2026 00:51
@vstinner
Copy link
Copy Markdown
Member

The CI is failing. Example:

======================================================================
ERROR: test_resize_bigger_on_multiline_function (test.test_pyrepl.test_unix_console.TestConsole.test_resize_bigger_on_multiline_function)
----------------------------------------------------------------------
Traceback (most recent call last):
  File "/home/runner/work/cpython/cpython-ro-srcdir/Lib/unittest/mock.py", line 1439, in patched
    return func(*newargs, **newkeywargs)
  File "/home/runner/work/cpython/cpython-ro-srcdir/Lib/test/test_pyrepl/test_unix_console.py", line 263, in test_resize_bigger_on_multiline_function
    _, con = handle_all_events(
             ~~~~~~~~~~~~~~~~~^
        [Event(evt="resize", data=None)],
        ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
        prepare_reader=same_reader,
        ^^^^^^^^^^^^^^^^^^^^^^^^^^^
        prepare_console=same_console,
        ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
    )
    ^
  File "/home/runner/work/cpython/cpython-ro-srcdir/Lib/test/test_pyrepl/support.py", line 105, in handle_all_events
    reader.handle1()
    ~~~~~~~~~~~~~~^^
  File "/home/runner/work/cpython/cpython-ro-srcdir/Lib/_pyrepl/reader.py", line 728, in handle1
    self.refresh()
    ~~~~~~~~~~~~^^
  File "/home/runner/work/cpython/cpython-ro-srcdir/Lib/_pyrepl/reader.py", line 647, in refresh
    self.console.height, self.console.width = self.console.getheightwidth()
    ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
ValueError: not enough values to unpack (expected 2, got 0)

======================================================================
ERROR: test_resize_smaller_on_multiline_function (test.test_pyrepl.test_unix_console.TestConsole.test_resize_smaller_on_multiline_function)
----------------------------------------------------------------------
Traceback (most recent call last):
  File "/home/runner/work/cpython/cpython-ro-srcdir/Lib/unittest/mock.py", line 1439, in patched
    return func(*newargs, **newkeywargs)
  File "/home/runner/work/cpython/cpython-ro-srcdir/Lib/test/test_pyrepl/test_unix_console.py", line 299, in test_resize_smaller_on_multiline_function
    _, con = handle_all_events(
             ~~~~~~~~~~~~~~~~~^
        [Event(evt="resize", data=None)],
        ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
        prepare_reader=same_reader,
        ^^^^^^^^^^^^^^^^^^^^^^^^^^^
        prepare_console=same_console,
        ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
    )
    ^
  File "/home/runner/work/cpython/cpython-ro-srcdir/Lib/test/test_pyrepl/support.py", line 105, in handle_all_events
    reader.handle1()
    ~~~~~~~~~~~~~~^^
  File "/home/runner/work/cpython/cpython-ro-srcdir/Lib/_pyrepl/reader.py", line 728, in handle1
    self.refresh()
    ~~~~~~~~~~~~^^
  File "/home/runner/work/cpython/cpython-ro-srcdir/Lib/_pyrepl/reader.py", line 647, in refresh
    self.console.height, self.console.width = self.console.getheightwidth()
    ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
ValueError: not enough values to unpack (expected 2, got 0)

@GabrielvMarinho GabrielvMarinho force-pushed the fix-repl-height-and-width-tracking-on-resize branch from 47c7453 to 1e7907a Compare March 27, 2026 18:52
@bedevere-app
Copy link
Copy Markdown

bedevere-app bot commented Mar 27, 2026

Most changes to Python require a NEWS entry. Add one using the blurb_it web app or the blurb command-line tool.

If this change has little impact on Python users, wait for a maintainer to apply the skip news label instead.

@GabrielvMarinho GabrielvMarinho force-pushed the fix-repl-height-and-width-tracking-on-resize branch from 1e7907a to 42dd0de Compare March 27, 2026 20:54
@bedevere-app
Copy link
Copy Markdown

bedevere-app bot commented Mar 27, 2026

Most changes to Python require a NEWS entry. Add one using the blurb_it web app or the blurb command-line tool.

If this change has little impact on Python users, wait for a maintainer to apply the skip news label instead.

@vstinner
Copy link
Copy Markdown
Member

If possible, try to avoid git push --force, it makes reviews harder.

@GabrielvMarinho
Copy link
Copy Markdown
Contributor Author

If possible, try to avoid git push --force, it makes reviews harder.

I had to git push --force some few times because i was rebasing, so its preferable to merge and do a new commit to get to the new state of the main?

@vstinner
Copy link
Copy Markdown
Member

so its preferable to merge and do a new commit to get to the new state of the main?

Yes, merge is preferred. Rebase is also causing troubles in reviews.

@GabrielvMarinho
Copy link
Copy Markdown
Contributor Author

so its preferable to merge and do a new commit to get to the new state of the main?

Yes, merge is preferred. Rebase is also causing troubles in reviews.

Thanks for the heads up, let me know if you need any help on the code review process.

Copy link
Copy Markdown
Member

@vstinner vstinner left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM. unix_console and window_console generates "resize" events. Before, the window_console didn't update the console height and width. Now, the code is generic in Reader.refresh().

@vstinner vstinner added needs backport to 3.14 bugs and security fixes needs backport to 3.13 bugs and security fixes labels Mar 27, 2026
@vstinner
Copy link
Copy Markdown
Member

You may add a NEWS entry to describe the fix.

@GabrielvMarinho
Copy link
Copy Markdown
Contributor Author

You may add a NEWS entry to describe the fix.

I just added it, is it OK that way?

Comment thread Misc/NEWS.d/next/Windows/2026-03-27-22-06-10.gh-issue-146458.fYj0UQ.rst Outdated
…Yj0UQ.rst

Co-authored-by: Victor Stinner <vstinner@python.org>
@vstinner vstinner merged commit 0b20bff into python:main Apr 7, 2026
59 checks passed
@miss-islington-app
Copy link
Copy Markdown

Thanks @GabrielvMarinho for the PR, and @vstinner for merging it 🌮🎉.. I'm working now to backport this PR to: 3.13, 3.14.
🐍🍒⛏🤖

@bedevere-app
Copy link
Copy Markdown

bedevere-app bot commented Apr 7, 2026

GH-148232 is a backport of this pull request to the 3.14 branch.

@miss-islington-app
Copy link
Copy Markdown

Sorry, @GabrielvMarinho and @vstinner, I could not cleanly backport this to 3.13 due to a conflict.
Please backport using cherry_picker on command line.

cherry_picker 0b20bff386141ee0e8c62da8366f674bad17e048 3.13

@bedevere-app bedevere-app bot removed the needs backport to 3.14 bugs and security fixes label Apr 7, 2026
@vstinner
Copy link
Copy Markdown
Member

vstinner commented Apr 7, 2026

There is a conflict on the 3.13 branch. I'm not sure how to solve it. In case of doubt, I prefer to not backport the change.

    def refresh(self) -> None:
        """Recalculate and refresh the screen."""
<<<<<<< HEAD
        if self.in_bracketed_paste and self.buffer and not self.buffer[-1] == "\n":
            return

=======
        self.console.height, self.console.width = self.console.getheightwidth()
>>>>>>> 0b20bff3861 (gh-146458: Fix REPL height and width tracking on resize (#146459))
        # this call sets up self.cxy, so call it first.
        self.screen = self.calc_screen()
        self.console.refresh(self.screen, self.cxy)
        self.dirty = False

@vstinner
Copy link
Copy Markdown
Member

vstinner commented Apr 7, 2026

PR merged, thanks for the fix @GabrielvMarinho.

vstinner added a commit that referenced this pull request Apr 7, 2026
…6459) (#148232)

gh-146458: Fix REPL height and width tracking on resize (GH-146459)
(cherry picked from commit 0b20bff)

Co-authored-by: Gabriel Volles Marinho <147559808+GabrielvMarinho@users.noreply.github.com>
Co-authored-by: blurb-it[bot] <43283697+blurb-it[bot]@users.noreply.github.com>
Co-authored-by: Victor Stinner <vstinner@python.org>
@bedevere-bot
Copy link
Copy Markdown

⚠️⚠️⚠️ Buildbot failure ⚠️⚠️⚠️

Hi! The buildbot AMD64 Windows Server 2022 NoGIL 3.x (tier-1) has failed when building commit 0b20bff.

What do you need to do:

  1. Don't panic.
  2. Check the buildbot page in the devguide if you don't know what the buildbots are or how they work.
  3. Go to the page of the buildbot that failed (https://buildbot.python.org/#/builders/1241/builds/8293) and take a look at the build logs.
  4. Check if the failure is related to this commit (0b20bff) or if it is a false positive.
  5. If the failure is related to this commit, please, reflect that on the issue and make a new Pull Request with a fix.

You can take a look at the buildbot page here:

https://buildbot.python.org/#/builders/1241/builds/8293

Summary of the results of the build (if available):

==

Click to see traceback logs
Traceback (most recent call last):
  File "C:\bbarea\3.x.itamaro-win64-srv-22-aws.x64.nogil\build\Lib\threading.py", line 1075, in _bootstrap_inner
    self._context.run(self.run)
    ~~~~~~~~~~~~~~~~~^^^^^^^^^^
  File "C:\bbarea\3.x.itamaro-win64-srv-22-aws.x64.nogil\build\Lib\threading.py", line 1017, in run
    self._target(*self._args, **self._kwargs)
    ~~~~~~~~~~~~^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "C:\bbarea\3.x.itamaro-win64-srv-22-aws.x64.nogil\build\Lib\multiprocessing\pool.py", line 595, in _handle_results
    cache[job]._set(i, obj)
    ~~~~~~~~~~~~~~~^^^^^^^^
  File "C:\bbarea\3.x.itamaro-win64-srv-22-aws.x64.nogil\build\Lib\multiprocessing\pool.py", line 783, in _set
    del self._cache[self._job]
        ~~~~~~~~~~~^^^^^^^^^^^
  File "C:\bbarea\3.x.itamaro-win64-srv-22-aws.x64.nogil\build\Lib\multiprocessing\pool.py", line 171, in __delitem__
    self.notifier.put(None)
    ~~~~~~~~~~~~~~~~~^^^^^^
  File "C:\bbarea\3.x.itamaro-win64-srv-22-aws.x64.nogil\build\Lib\multiprocessing\queues.py", line 394, in put
    self._writer.send_bytes(obj)
    ~~~~~~~~~~~~~~~~~~~~~~~^^^^^
  File "C:\bbarea\3.x.itamaro-win64-srv-22-aws.x64.nogil\build\Lib\multiprocessing\connection.py", line 207, in send_bytes
    self._send_bytes(m[offset:offset + size])
    ~~~~~~~~~~~~~~~~^^^^^^^^^^^^^^^^^^^^^^^^^
  File "C:\bbarea\3.x.itamaro-win64-srv-22-aws.x64.nogil\build\Lib\multiprocessing\connection.py", line 294, in _send_bytes
    raise ValueError("concurrent send_bytes() calls "
                     "are not supported")
ValueError: concurrent send_bytes() calls are not supported
k

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

needs backport to 3.13 bugs and security fixes

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants