Skip to content

GH-130328: Speedup pasting in legacy console on Windows #133728

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

Merged
merged 4 commits into from
May 25, 2025

Conversation

chris-eibl
Copy link
Member

@chris-eibl chris-eibl commented May 9, 2025

for i in range(rec_count):
rec = recs[i]
# In case of a legacy console, we do not only receive a keydown
Copy link
Member Author

Choose a reason for hiding this comment

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

Actually, there is a lot of duplicated logic from get_event now. Maybe refactor that, so the logic can be reused here?

@@ -449,8 +442,11 @@ def get_event(self, block: bool = True) -> Event | None:
and there is no event pending, otherwise waits for the
completion of an event."""

if not block and not self.wait(timeout=0):
Copy link
Member Author

Choose a reason for hiding this comment

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

I have moved blocking and waiting logic into get_event like in unix_console.py. IMHO that shouldn't be part of reading and we're in perfect sync with Unix now.

@@ -484,7 +491,6 @@ def do(self) -> None:
data = ""
start = time.time()
while done not in data:
self.reader.console.wait(100)
Copy link
Member Author

Choose a reason for hiding this comment

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

I don't think this is needed. Works for me without it. For both, Linux and Windows, this will immediately return in case of pending data, and just needlessly waits 100 ms if there is no more data.

Copy link
Contributor

@ambv ambv left a comment

Choose a reason for hiding this comment

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

This is perfect. You utilized my getpending() implementation without adding any double-buffering. It is indeed speeding things up dramatically while not breaking the existing bracketed paste behavior.

@ambv ambv added the needs backport to 3.14 bugs and security fixes label May 25, 2025
@ambv ambv merged commit 91b4886 into python:main May 25, 2025
53 checks passed
@miss-islington-app
Copy link

Thanks @chris-eibl for the PR, and @ambv for merging it 🌮🎉.. I'm working now to backport this PR to: 3.14.
🐍🍒⛏🤖

miss-islington pushed a commit to miss-islington/cpython that referenced this pull request May 25, 2025
…gh-133728)

(cherry picked from commit 91b4886)

Co-authored-by: Chris Eibl <138194463+chris-eibl@users.noreply.github.com>
@bedevere-app
Copy link

bedevere-app bot commented May 25, 2025

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

@bedevere-app bedevere-app bot removed the needs backport to 3.14 bugs and security fixes label May 25, 2025
ambv pushed a commit that referenced this pull request May 25, 2025
…3728) (#134653)

(cherry picked from commit 91b4886)

Co-authored-by: Chris Eibl <138194463+chris-eibl@users.noreply.github.com>
@bedevere-bot
Copy link

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

Hi! The buildbot AMD64 Windows10 3.x (tier-1) has failed when building commit 91b4886.

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/146/builds/11526) and take a look at the build logs.
  4. Check if the failure is related to this commit (91b4886) 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/146/builds/11526

Failed tests:

  • test_pyrepl

Failed subtests:

  • test_up_vt - test.test_pyrepl.test_windows_console.WindowsConsoleGetEventTests.test_up_vt
  • test_left - test.test_pyrepl.test_windows_console.WindowsConsoleGetEventTests.test_left
  • test_KEY_EVENT_up_ignored - test.test_pyrepl.test_windows_console.WindowsConsoleGetEventTests.test_KEY_EVENT_up_ignored
  • test_enter_vt - test.test_pyrepl.test_windows_console.WindowsConsoleGetEventTests.test_enter_vt
  • test_m_LEFT_ALT_PRESSED_and_LEFT_CTRL_PRESSED - test.test_pyrepl.test_windows_console.WindowsConsoleGetEventTests.test_m_LEFT_ALT_PRESSED_and_LEFT_CTRL_PRESSED
  • test_WINDOW_BUFFER_SIZE_EVENT - test.test_pyrepl.test_windows_console.WindowsConsoleGetEventTests.test_WINDOW_BUFFER_SIZE_EVENT
  • test_backspace_vt - test.test_pyrepl.test_windows_console.WindowsConsoleGetEventTests.test_backspace_vt
  • test_left_RIGHT_CTRL_PRESSED - test.test_pyrepl.test_windows_console.WindowsConsoleGetEventTests.test_left_RIGHT_CTRL_PRESSED
  • test_AltGr_m - test.test_pyrepl.test_windows_console.WindowsConsoleGetEventTests.test_AltGr_m
  • test_EmptyBuffer - test.test_pyrepl.test_windows_console.WindowsConsoleGetEventTests.test_EmptyBuffer
  • test_unhandled_events - test.test_pyrepl.test_windows_console.WindowsConsoleGetEventTests.test_unhandled_events
  • test_left_RIGHT_ALT_PRESSED - test.test_pyrepl.test_windows_console.WindowsConsoleGetEventTests.test_left_RIGHT_ALT_PRESSED
  • test_AltGr_7 - test.test_pyrepl.test_windows_console.WindowsConsoleGetEventTests.test_AltGr_7
  • test_m_LEFT_ALT_PRESSED - test.test_pyrepl.test_windows_console.WindowsConsoleGetEventTests.test_m_LEFT_ALT_PRESSED
  • test_backspace - test.test_pyrepl.test_windows_console.WindowsConsoleGetEventTests.test_backspace
  • test_enter - test.test_pyrepl.test_windows_console.WindowsConsoleGetEventTests.test_enter
  • test_M - test.test_pyrepl.test_windows_console.WindowsConsoleGetEventTests.test_M
  • test_m - test.test_pyrepl.test_windows_console.WindowsConsoleGetEventTests.test_m
  • test_umlaut_a_german - test.test_pyrepl.test_windows_console.WindowsConsoleGetEventTests.test_umlaut_a_german
  • test_left_LEFT_ALT_PRESSED - test.test_pyrepl.test_windows_console.WindowsConsoleGetEventTests.test_left_LEFT_ALT_PRESSED
  • test_left_LEFT_CTRL_PRESSED - test.test_pyrepl.test_windows_console.WindowsConsoleGetEventTests.test_left_LEFT_CTRL_PRESSED
  • test_m_RIGHT_ALT_PRESSED - test.test_pyrepl.test_windows_console.WindowsConsoleGetEventTests.test_m_RIGHT_ALT_PRESSED

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

==

Click to see traceback logs
Traceback (most recent call last):
  File "D:\buildarea\3.x.bolen-windows10\build\Lib\test\test_pyrepl\test_windows_console.py", line 415, in test_WINDOW_BUFFER_SIZE_EVENT
    self.assertEqual(self.get_event([ir]), Event("resize", ""))
    ~~~~~~~~~~~~~~~~^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
AssertionError: None != Event(evt='resize', data='', raw=b'')


Traceback (most recent call last):
  File "D:\buildarea\3.x.bolen-windows10\build\Lib\test\test_pyrepl\test_windows_console.py", line 466, in test_left_RIGHT_CTRL_PRESSED
    self.assertEqual(
    ~~~~~~~~~~~~~~~~^
        self.get_event([ir]), Event("key", "ctrl left"))
        ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
AssertionError: None != Event(evt='key', data='ctrl left', raw=b'')


Traceback (most recent call last):
  File "D:\buildarea\3.x.bolen-windows10\build\Lib\test\test_pyrepl\test_windows_console.py", line 534, in test_AltGr_7
    self.assertEqual(self.get_event([ir]), Event("key", "{"))
    ~~~~~~~~~~~~~~~~^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
AssertionError: None != Event(evt='key', data='{', raw=b'')


Traceback (most recent call last):
  File "D:\buildarea\3.x.bolen-windows10\build\Lib\test\test_pyrepl\test_windows_console.py", line 454, in test_M
    self.assertEqual(self.get_event([ir]), Event("key", "M"))
    ~~~~~~~~~~~~~~~~^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
AssertionError: None != Event(evt='key', data='M', raw=b'')


Traceback (most recent call last):
  File "D:\buildarea\3.x.bolen-windows10\build\Lib\test\test_pyrepl\test_windows_console.py", line 562, in test_enter_vt
    self.assertEqual(self.get_event([ir], vt_support=True),
    ~~~~~~~~~~~~~~~~^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
                     Event("key", "\n"))
                     ^^^^^^^^^^^^^^^^^^^
AssertionError: None != Event(evt='key', data='\n', raw=b'')


Traceback (most recent call last):
  File "D:\buildarea\3.x.bolen-windows10\build\Lib\test\test_pyrepl\test_windows_console.py", line 449, in test_m
    self.assertEqual(self.get_event([ir]), Event("key", "m"))
    ~~~~~~~~~~~~~~~~^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
AssertionError: None != Event(evt='key', data='m', raw=b'')


Traceback (most recent call last):
  File "D:\buildarea\3.x.bolen-windows10\build\Lib\test\test_pyrepl\test_windows_console.py", line 510, in test_m_LEFT_ALT_PRESSED
    self.assertEqual(self.get_event([ir]), Event(evt="key", data="\033"))
    ~~~~~~~~~~~~~~~~^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
AssertionError: None != Event(evt='key', data='\x1b', raw=b'')


Traceback (most recent call last):
  File "D:\buildarea\3.x.bolen-windows10\build\Lib\test\test_pyrepl\test_windows_console.py", line 548, in test_umlaut_a_german
    self.assertEqual(self.get_event([ir]), Event("key", ""))
    ~~~~~~~~~~~~~~~~^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
AssertionError: None != Event(evt='key', data='�', raw=b'')


Traceback (most recent call last):
  File "D:\buildarea\3.x.bolen-windows10\build\Lib\test\test_pyrepl\test_windows_console.py", line 517, in test_m_RIGHT_ALT_PRESSED
    self.assertEqual(self.get_event([ir]), Event(evt="key", data="\033"))
    ~~~~~~~~~~~~~~~~^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
AssertionError: None != Event(evt='key', data='\x1b', raw=b'')


Traceback (most recent call last):
  File "D:\buildarea\3.x.bolen-windows10\build\Lib\test\test_pyrepl\test_windows_console.py", line 543, in test_AltGr_m
    self.assertEqual(self.get_event([ir]), Event("key", ""))
    ~~~~~~~~~~~~~~~~^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
AssertionError: None != Event(evt='key', data='�', raw=b'')


Traceback (most recent call last):
  File "D:\buildarea\3.x.bolen-windows10\build\Lib\test\test_pyrepl\test_windows_console.py", line 443, in test_backspace
    self.assertEqual(
    ~~~~~~~~~~~~~~~~^
        self.get_event([ir]), Event("key", "backspace"))
        ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
AssertionError: None != Event(evt='key', data='backspace', raw=b'')


Traceback (most recent call last):
  File "D:\buildarea\3.x.bolen-windows10\build\Lib\test\test_pyrepl\test_windows_console.py", line 473, in test_left_LEFT_CTRL_PRESSED
    self.assertEqual(
    ~~~~~~~~~~~~~~~~^
        self.get_event([ir]), Event("key", "ctrl left"))
        ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
AssertionError: None != Event(evt='key', data='ctrl left', raw=b'')


Traceback (most recent call last):
  File "D:\buildarea\3.x.bolen-windows10\build\Lib\test\test_pyrepl\test_windows_console.py", line 480, in test_left_RIGHT_ALT_PRESSED
    self.assertEqual(self.get_event([ir]), Event(evt="key", data="\033"))
    ~~~~~~~~~~~~~~~~^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
AssertionError: None != Event(evt='key', data='\x1b', raw=b'')


Traceback (most recent call last):
  File "D:\buildarea\3.x.bolen-windows10\build\Lib\test\test_pyrepl\test_windows_console.py", line 460, in test_left
    self.assertEqual(self.get_event([ir]), Event("key", "left"))
    ~~~~~~~~~~~~~~~~^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
AssertionError: None != Event(evt='key', data='left', raw=b'')


Traceback (most recent call last):
  File "D:\buildarea\3.x.bolen-windows10\build\Lib\test\test_pyrepl\test_windows_console.py", line 434, in test_unhandled_events
    self.assertEqual(self.mock.call_count, 1)
    ~~~~~~~~~~~~~~~~^^^^^^^^^^^^^^^^^^^^^^^^^
AssertionError: 0 != 1


Traceback (most recent call last):
  File "D:\buildarea\3.x.bolen-windows10\build\Lib\test\test_pyrepl\test_windows_console.py", line 438, in test_enter
    self.assertEqual(self.get_event([ir]), Event("key", "\n"))
    ~~~~~~~~~~~~~~~~^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
AssertionError: None != Event(evt='key', data='\n', raw=b'')


Traceback (most recent call last):
  File "D:\buildarea\3.x.bolen-windows10\build\Lib\test\test_pyrepl\test_windows_console.py", line 407, in test_EmptyBuffer
    self.assertEqual(self.mock.call_count, 1)
    ~~~~~~~~~~~~~~~~^^^^^^^^^^^^^^^^^^^^^^^^^
AssertionError: 0 != 1


Traceback (most recent call last):
  File "D:\buildarea\3.x.bolen-windows10\build\Lib\test\test_pyrepl\test_windows_console.py", line 490, in test_left_LEFT_ALT_PRESSED
    self.assertEqual(self.get_event([ir]), Event(evt="key", data="\033"))
    ~~~~~~~~~~~~~~~~^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
AssertionError: None != Event(evt='key', data='\x1b', raw=b'')


Traceback (most recent call last):
  File "D:\buildarea\3.x.bolen-windows10\build\Lib\test\test_pyrepl\test_windows_console.py", line 574, in test_up_vt
    self.assertEqual(self.get_event(irs, vt_support=True),
    ~~~~~~~~~~~~~~~~^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
                     Event(evt='key', data='up', raw=bytearray(b'\x1b[A')))
                     ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
AssertionError: None != Event(evt='key', data='up', raw=bytearray(b'\x1b[A'))


Traceback (most recent call last):
  File "D:\buildarea\3.x.bolen-windows10\build\Lib\test\test_pyrepl\test_windows_console.py", line 505, in test_m_LEFT_ALT_PRESSED_and_LEFT_CTRL_PRESSED
    self.assertEqual(self.mock.call_count, 1)
    ~~~~~~~~~~~~~~~~^^^^^^^^^^^^^^^^^^^^^^^^^
AssertionError: 0 != 1


Traceback (most recent call last):
  File "D:\buildarea\3.x.bolen-windows10\build\Lib\test\test_pyrepl\test_windows_console.py", line 568, in test_backspace_vt
    self.assertEqual(self.get_event([ir], vt_support=True),
    ~~~~~~~~~~~~~~~~^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
                     Event("key", "backspace", b"\x7f"))
                     ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
AssertionError: None != Event(evt='key', data='backspace', raw=b'\x7f')


Traceback (most recent call last):
  File "D:\buildarea\3.x.bolen-windows10\build\Lib\test\test_pyrepl\test_windows_console.py", line 424, in test_KEY_EVENT_up_ignored
    self.assertEqual(self.mock.call_count, 1)
    ~~~~~~~~~~~~~~~~^^^^^^^^^^^^^^^^^^^^^^^^^
AssertionError: 0 != 1

@ambv
Copy link
Contributor

ambv commented May 25, 2025

@chris-eibl this buildbot failure ^^^ is real. I can't explain that yet and cannot reproduce it locally on Win 11, but if I don't manage to fix it before tomorrow's 3.14 beta 2, I will have to revert the backport.

@bedevere-bot
Copy link

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

Hi! The buildbot AMD64 Windows10 3.14 (tier-1) has failed when building commit 93aee56.

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/1711/builds/99) and take a look at the build logs.
  4. Check if the failure is related to this commit (93aee56) 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/1711/builds/99

Failed tests:

  • test_pyrepl

Failed subtests:

  • test_up_vt - test.test_pyrepl.test_windows_console.WindowsConsoleGetEventTests.test_up_vt
  • test_left - test.test_pyrepl.test_windows_console.WindowsConsoleGetEventTests.test_left
  • test_KEY_EVENT_up_ignored - test.test_pyrepl.test_windows_console.WindowsConsoleGetEventTests.test_KEY_EVENT_up_ignored
  • test_enter_vt - test.test_pyrepl.test_windows_console.WindowsConsoleGetEventTests.test_enter_vt
  • test_m_LEFT_ALT_PRESSED_and_LEFT_CTRL_PRESSED - test.test_pyrepl.test_windows_console.WindowsConsoleGetEventTests.test_m_LEFT_ALT_PRESSED_and_LEFT_CTRL_PRESSED
  • test_WINDOW_BUFFER_SIZE_EVENT - test.test_pyrepl.test_windows_console.WindowsConsoleGetEventTests.test_WINDOW_BUFFER_SIZE_EVENT
  • test_backspace_vt - test.test_pyrepl.test_windows_console.WindowsConsoleGetEventTests.test_backspace_vt
  • test_left_RIGHT_CTRL_PRESSED - test.test_pyrepl.test_windows_console.WindowsConsoleGetEventTests.test_left_RIGHT_CTRL_PRESSED
  • test_AltGr_m - test.test_pyrepl.test_windows_console.WindowsConsoleGetEventTests.test_AltGr_m
  • test_EmptyBuffer - test.test_pyrepl.test_windows_console.WindowsConsoleGetEventTests.test_EmptyBuffer
  • test_unhandled_events - test.test_pyrepl.test_windows_console.WindowsConsoleGetEventTests.test_unhandled_events
  • test_left_RIGHT_ALT_PRESSED - test.test_pyrepl.test_windows_console.WindowsConsoleGetEventTests.test_left_RIGHT_ALT_PRESSED
  • test_AltGr_7 - test.test_pyrepl.test_windows_console.WindowsConsoleGetEventTests.test_AltGr_7
  • test_m_LEFT_ALT_PRESSED - test.test_pyrepl.test_windows_console.WindowsConsoleGetEventTests.test_m_LEFT_ALT_PRESSED
  • test_backspace - test.test_pyrepl.test_windows_console.WindowsConsoleGetEventTests.test_backspace
  • test_enter - test.test_pyrepl.test_windows_console.WindowsConsoleGetEventTests.test_enter
  • test_M - test.test_pyrepl.test_windows_console.WindowsConsoleGetEventTests.test_M
  • test_m - test.test_pyrepl.test_windows_console.WindowsConsoleGetEventTests.test_m
  • test_umlaut_a_german - test.test_pyrepl.test_windows_console.WindowsConsoleGetEventTests.test_umlaut_a_german
  • test_left_LEFT_ALT_PRESSED - test.test_pyrepl.test_windows_console.WindowsConsoleGetEventTests.test_left_LEFT_ALT_PRESSED
  • test_left_LEFT_CTRL_PRESSED - test.test_pyrepl.test_windows_console.WindowsConsoleGetEventTests.test_left_LEFT_CTRL_PRESSED
  • test_m_RIGHT_ALT_PRESSED - test.test_pyrepl.test_windows_console.WindowsConsoleGetEventTests.test_m_RIGHT_ALT_PRESSED

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

==

Click to see traceback logs
Traceback (most recent call last):
  File "D:\buildarea\3.14.bolen-windows10\build\Lib\test\test_pyrepl\test_windows_console.py", line 466, in test_left_RIGHT_CTRL_PRESSED
    self.assertEqual(
    ~~~~~~~~~~~~~~~~^
        self.get_event([ir]), Event("key", "ctrl left"))
        ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
AssertionError: None != Event(evt='key', data='ctrl left', raw=b'')


Traceback (most recent call last):
  File "D:\buildarea\3.14.bolen-windows10\build\Lib\test\test_pyrepl\test_windows_console.py", line 449, in test_m
    self.assertEqual(self.get_event([ir]), Event("key", "m"))
    ~~~~~~~~~~~~~~~~^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
AssertionError: None != Event(evt='key', data='m', raw=b'')


Traceback (most recent call last):
  File "D:\buildarea\3.14.bolen-windows10\build\Lib\test\test_pyrepl\test_windows_console.py", line 480, in test_left_RIGHT_ALT_PRESSED
    self.assertEqual(self.get_event([ir]), Event(evt="key", data="\033"))
    ~~~~~~~~~~~~~~~~^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
AssertionError: None != Event(evt='key', data='\x1b', raw=b'')


Traceback (most recent call last):
  File "D:\buildarea\3.14.bolen-windows10\build\Lib\test\test_pyrepl\test_windows_console.py", line 473, in test_left_LEFT_CTRL_PRESSED
    self.assertEqual(
    ~~~~~~~~~~~~~~~~^
        self.get_event([ir]), Event("key", "ctrl left"))
        ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
AssertionError: None != Event(evt='key', data='ctrl left', raw=b'')


Traceback (most recent call last):
  File "D:\buildarea\3.14.bolen-windows10\build\Lib\test\test_pyrepl\test_windows_console.py", line 407, in test_EmptyBuffer
    self.assertEqual(self.mock.call_count, 1)
    ~~~~~~~~~~~~~~~~^^^^^^^^^^^^^^^^^^^^^^^^^
AssertionError: 0 != 1


Traceback (most recent call last):
  File "D:\buildarea\3.14.bolen-windows10\build\Lib\test\test_pyrepl\test_windows_console.py", line 454, in test_M
    self.assertEqual(self.get_event([ir]), Event("key", "M"))
    ~~~~~~~~~~~~~~~~^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
AssertionError: None != Event(evt='key', data='M', raw=b'')


Traceback (most recent call last):
  File "D:\buildarea\3.14.bolen-windows10\build\Lib\test\test_pyrepl\test_windows_console.py", line 438, in test_enter
    self.assertEqual(self.get_event([ir]), Event("key", "\n"))
    ~~~~~~~~~~~~~~~~^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
AssertionError: None != Event(evt='key', data='\n', raw=b'')


Traceback (most recent call last):
  File "D:\buildarea\3.14.bolen-windows10\build\Lib\test\test_pyrepl\test_windows_console.py", line 460, in test_left
    self.assertEqual(self.get_event([ir]), Event("key", "left"))
    ~~~~~~~~~~~~~~~~^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
AssertionError: None != Event(evt='key', data='left', raw=b'')


Traceback (most recent call last):
  File "D:\buildarea\3.14.bolen-windows10\build\Lib\test\test_pyrepl\test_windows_console.py", line 424, in test_KEY_EVENT_up_ignored
    self.assertEqual(self.mock.call_count, 1)
    ~~~~~~~~~~~~~~~~^^^^^^^^^^^^^^^^^^^^^^^^^
AssertionError: 0 != 1


Traceback (most recent call last):
  File "D:\buildarea\3.14.bolen-windows10\build\Lib\test\test_pyrepl\test_windows_console.py", line 568, in test_backspace_vt
    self.assertEqual(self.get_event([ir], vt_support=True),
    ~~~~~~~~~~~~~~~~^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
                     Event("key", "backspace", b"\x7f"))
                     ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
AssertionError: None != Event(evt='key', data='backspace', raw=b'\x7f')


Traceback (most recent call last):
  File "D:\buildarea\3.14.bolen-windows10\build\Lib\test\test_pyrepl\test_windows_console.py", line 534, in test_AltGr_7
    self.assertEqual(self.get_event([ir]), Event("key", "{"))
    ~~~~~~~~~~~~~~~~^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
AssertionError: None != Event(evt='key', data='{', raw=b'')


Traceback (most recent call last):
  File "D:\buildarea\3.14.bolen-windows10\build\Lib\test\test_pyrepl\test_windows_console.py", line 510, in test_m_LEFT_ALT_PRESSED
    self.assertEqual(self.get_event([ir]), Event(evt="key", data="\033"))
    ~~~~~~~~~~~~~~~~^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
AssertionError: None != Event(evt='key', data='\x1b', raw=b'')


Traceback (most recent call last):
  File "D:\buildarea\3.14.bolen-windows10\build\Lib\test\test_pyrepl\test_windows_console.py", line 548, in test_umlaut_a_german
    self.assertEqual(self.get_event([ir]), Event("key", ""))
    ~~~~~~~~~~~~~~~~^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
AssertionError: None != Event(evt='key', data='�', raw=b'')


Traceback (most recent call last):
  File "D:\buildarea\3.14.bolen-windows10\build\Lib\test\test_pyrepl\test_windows_console.py", line 415, in test_WINDOW_BUFFER_SIZE_EVENT
    self.assertEqual(self.get_event([ir]), Event("resize", ""))
    ~~~~~~~~~~~~~~~~^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
AssertionError: None != Event(evt='resize', data='', raw=b'')


Traceback (most recent call last):
  File "D:\buildarea\3.14.bolen-windows10\build\Lib\test\test_pyrepl\test_windows_console.py", line 543, in test_AltGr_m
    self.assertEqual(self.get_event([ir]), Event("key", ""))
    ~~~~~~~~~~~~~~~~^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
AssertionError: None != Event(evt='key', data='�', raw=b'')


Traceback (most recent call last):
  File "D:\buildarea\3.14.bolen-windows10\build\Lib\test\test_pyrepl\test_windows_console.py", line 574, in test_up_vt
    self.assertEqual(self.get_event(irs, vt_support=True),
    ~~~~~~~~~~~~~~~~^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
                     Event(evt='key', data='up', raw=bytearray(b'\x1b[A')))
                     ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
AssertionError: None != Event(evt='key', data='up', raw=bytearray(b'\x1b[A'))


Traceback (most recent call last):
  File "D:\buildarea\3.14.bolen-windows10\build\Lib\test\test_pyrepl\test_windows_console.py", line 434, in test_unhandled_events
    self.assertEqual(self.mock.call_count, 1)
    ~~~~~~~~~~~~~~~~^^^^^^^^^^^^^^^^^^^^^^^^^
AssertionError: 0 != 1


Traceback (most recent call last):
  File "D:\buildarea\3.14.bolen-windows10\build\Lib\test\test_pyrepl\test_windows_console.py", line 517, in test_m_RIGHT_ALT_PRESSED
    self.assertEqual(self.get_event([ir]), Event(evt="key", data="\033"))
    ~~~~~~~~~~~~~~~~^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
AssertionError: None != Event(evt='key', data='\x1b', raw=b'')


Traceback (most recent call last):
  File "D:\buildarea\3.14.bolen-windows10\build\Lib\test\test_pyrepl\test_windows_console.py", line 490, in test_left_LEFT_ALT_PRESSED
    self.assertEqual(self.get_event([ir]), Event(evt="key", data="\033"))
    ~~~~~~~~~~~~~~~~^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
AssertionError: None != Event(evt='key', data='\x1b', raw=b'')


Traceback (most recent call last):
  File "D:\buildarea\3.14.bolen-windows10\build\Lib\test\test_pyrepl\test_windows_console.py", line 505, in test_m_LEFT_ALT_PRESSED_and_LEFT_CTRL_PRESSED
    self.assertEqual(self.mock.call_count, 1)
    ~~~~~~~~~~~~~~~~^^^^^^^^^^^^^^^^^^^^^^^^^
AssertionError: 0 != 1


Traceback (most recent call last):
  File "D:\buildarea\3.14.bolen-windows10\build\Lib\test\test_pyrepl\test_windows_console.py", line 443, in test_backspace
    self.assertEqual(
    ~~~~~~~~~~~~~~~~^
        self.get_event([ir]), Event("key", "backspace"))
        ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
AssertionError: None != Event(evt='key', data='backspace', raw=b'')


Traceback (most recent call last):
  File "D:\buildarea\3.14.bolen-windows10\build\Lib\test\test_pyrepl\test_windows_console.py", line 562, in test_enter_vt
    self.assertEqual(self.get_event([ir], vt_support=True),
    ~~~~~~~~~~~~~~~~^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
                     Event("key", "\n"))
                     ^^^^^^^^^^^^^^^^^^^
AssertionError: None != Event(evt='key', data='\n', raw=b'')

@chris-eibl
Copy link
Member Author

chris-eibl commented May 25, 2025

I can reproduce these failures on Windows 10, too, for both main and 3.14 when running in a legacy console. In fact, the fix is simple:

--- a/Lib/test/test_pyrepl/test_windows_console.py
+++ b/Lib/test/test_pyrepl/test_windows_console.py
@@ -386,6 +386,7 @@ def get_event(self, input_records, **kwargs) -> Console:
         self.console._read_input = self.mock
         self.console._WindowsConsole__vt_support = kwargs.get("vt_support",
                                                               False)
+        self.console.wait = MagicMock(return_value=True)

in these tests I've introduced in #132439. They shouldn't depend on wait, which was moved in this PR into get_event. Particulary WaitForSingleObject(InHandle) is no good here, and I just wonder now, why they pass when the tests are run in a Windows terminal.

I must have run the tests back then in a Windows terminal, and most probably all the GH bots are Windows 11 based, too?

@chris-eibl
Copy link
Member Author

Do you want me to create a PR or is the above diff sufficient?

miss-islington pushed a commit to miss-islington/cpython that referenced this pull request May 25, 2025
pythongh-134660)

(cherry picked from commit 1000283)

Co-authored-by: Chris Eibl <138194463+chris-eibl@users.noreply.github.com>
ambv pushed a commit that referenced this pull request May 25, 2025
…-134660) (gh-134666)

(cherry picked from commit 1000283)

Co-authored-by: Chris Eibl <138194463+chris-eibl@users.noreply.github.com>
@chris-eibl chris-eibl deleted the speedup_paste_legacy branch May 26, 2025 05:55
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants