Uh oh!
There was an error while loading.Please reload this page.
- Notifications
You must be signed in to change notification settings - Fork34k
gh-128067: Fix pyrepl overriding printed output without newlines#138732
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 ourterms of service andprivacy statement. We’ll occasionally send you account related emails.
Already on GitHub?Sign in to your account
Uh oh!
There was an error while loading.Please reload this page.
Conversation
Most changes to Pythonrequire a NEWS entry. Add one using theblurb_it web app or theblurb command-line tool. If this change has little impact on Python users, wait for a maintainer to apply the |
Most changes to Pythonrequire a NEWS entry. Add one using theblurb_it web app or theblurb command-line tool. If this change has little impact on Python users, wait for a maintainer to apply the |
Most changes to Pythonrequire a NEWS entry. Add one using theblurb_it web app or theblurb command-line tool. If this change has little impact on Python users, wait for a maintainer to apply the |
chris-eibl commentedSep 14, 2025
As written in the issue, this works fine on
|
Uh oh!
There was an error while loading.Please reload this page.
| self._move_relative(0, len(self.screen) - 1) | ||
| self.__write("\n") | ||
| if self.screen: | ||
| self._move_relative(0, len(self.screen) - 1) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others.Learn more.
Spot on,len(self.screen) - 1 should not get negative here.
chris-eibl commentedSep 14, 2025
Please add a News entry, seeQuick reference #8 in the devguide. |
chris-eibl commentedSep 14, 2025
Please merge with latest default, because the pyrepl Windows tests are not run otherwise (#138801). |
JanEricNitschke commentedSep 14, 2025
So merge with current main and "merge" not "rebase", right? So basically just clicking the "Update branch" button here. |
chris-eibl commentedSep 14, 2025
I suggest to add tests like deftest_no_newline(self,_os_write):code="1"events=code_to_events(code)_,con=handle_events_unix_console(events)self.assertNotIn(call(ANY,b'\n'),_os_write.mock_calls)con.restore()deftest_newline(self,_os_write):code="\n"events=code_to_events(code)_,con=handle_events_unix_console(events)_os_write.assert_any_call(ANY,b"\n")con.restore() in I think they are best placed before Both tests fail before the PR and succeed with the PR. So these tests might be enough, but of course your current test is more explict. But since Windows doesn't have thepty (Pseudo-terminal utilities), I don't know how to do a similar test there. The filtering of the many escape sequences might induce some maintenance burden, but I don't think it is a big issue. |
chris-eibl commentedSep 14, 2025
Correct. For reviewers it is easier to follow without squashing. For the final merge from your fork to the upstream branch, squashing is used, anyway. |
JanEricNitschke commentedSep 14, 2025
Added the tests. I put the news entry under Windows because the main user visible effect here is on windows, although we did make changes to both unix and windows consoles. |
chris-eibl left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others.Learn more.
LGTM. Thank you@JanEricNitschke.
chris-eibl commentedSep 14, 2025
I just found out, that in cpython/Lib/_pyrepl/windows_console.py Line 517 in8b5ce31
to cpython/Lib/_pyrepl/unix_console.py Line 562 in1c984ba
like in unix_console.py (and like it is initialized inprepare in both implementations). |
JanEricNitschke commentedSep 14, 2025 • edited
Loading Uh oh!
There was an error while loading.Please reload this page.
edited
Uh oh!
There was an error while loading.Please reload this page.
Changed this for the windows console to be the same as for the unix one. |
JanEricNitschke commentedSep 16, 2025
Added myself to ACKS after the review/approval, hope thats alright. |
| self.__write(CLEAR) | ||
| self.posxy = 0, 0 | ||
| self.screen = [""] | ||
| self.screen = [] |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others.Learn more.
The "" here before was a clear attempt at working around the same issue that you're solving here, but I agree theif statement is cleaner and more explicit.
Inunix_console.pyclear() is settingself.screen to an empty list, but as you noticed this wasn't triggering any bug because the__gone_tall boolean would prevent this path being taken inrefresh(). In unit tests that wasn't the case and so they were failing before your fix.
I'm okay with being defensive here, especially that this makes the behavior symmetrical between Windows and Unix.
ambv commentedJan 2, 2026
Sorry this took me so long to get to. I had to understand what's going on here before pushing the green button. Confirmed this is the correct fix and tested it resolves the issue on Windows 11 while maintaining behavior on macOS and Ubuntu 22.04 LTS. Thank you so much for your work,@JanEricNitschke and@chris-eibl for your careful review. |
8a2deea intopython:mainUh oh!
There was an error while loading.Please reload this page.
Thanks@JanEricNitschke for the PR, and@ambv for merging it 🌮🎉.. I'm working now to backport this PR to: 3.13, 3.14. |
pythonGH-138732)(cherry picked from commit8a2deea)Co-authored-by: Jan-Eric Nitschke <47750513+JanEricNitschke@users.noreply.github.com>Co-authored-by: Łukasz Langa <lukasz@langa.pl>
GH-143350 is a backport of this pull request to the3.14 branch. |
pythonGH-138732)(cherry picked from commit8a2deea)Co-authored-by: Jan-Eric Nitschke <47750513+JanEricNitschke@users.noreply.github.com>Co-authored-by: Łukasz Langa <lukasz@langa.pl>
GH-143351 is a backport of this pull request to the3.13 branch. |
bedevere-bot commentedJan 2, 2026
|
ambv commentedJan 2, 2026
The buildbot failure is related. I'm on it. |
Uh oh!
There was an error while loading.Please reload this page.
I tried a bit to debug this and narrowed it down to these two lines for windows and unix terminals respectively:
Because while properly running the repl in unix doesnt cause the issue, running the test i added also fails there before these changes.
I am not 100% sure if this is the base and 100% correct way, but it causes the test to pass on unix and fixes the issue on windows for me.
I also attempted to try to be able to run these tests for windows (because thats where we actually saw the issue) but didnt manage unfortunately.
With the fix in the unix console:
Without: