◐ Shell
reader mode source ↗
Skip to content

GH-132439: Fix REPL swallowing characters entered with AltGr on cmd.exe#132440

Merged
ambv merged 13 commits into
python:mainfrom
chris-eibl:fix_altgr
May 5, 2025
Merged

GH-132439: Fix REPL swallowing characters entered with AltGr on cmd.exe#132440
ambv merged 13 commits into
python:mainfrom
chris-eibl:fix_altgr

Conversation

@chris-eibl

@chris-eibl chris-eibl commented Apr 12, 2025

Copy link
Copy Markdown
Member

E.g. on my keyboard with German layout, { is usually entered via pressing the AltGr key and 7, i.e. AltGr+7.

Likewise, }, [, ], \ and some more can only be entered via AltGr.

But since #128388 / #128389 these are swallowed by the REPL on Windows and can no longer be entered.

This happens in legacy Windows terminals, where the virtual terminal mode is turned off (e.g. cmd.exe).

In virtual terminal mode there are other issues, see #131878.

@chris-eibl chris-eibl added OS-windows 3.13 bugs and security fixes 3.14 topic-repl Related to the interactive shell labels Apr 12, 2025
@chris-eibl chris-eibl requested a review from vstinner April 12, 2025 14:49
@chris-eibl

Copy link
Copy Markdown
Member Author

Adding @vstinner, @eendebakpt and @paulie4 , since they were involved in #128389 and already talked about AltGr.

@chris-eibl

Copy link
Copy Markdown
Member Author

PS: switching to an english keyboard layout, I can use the AltGr key like right-Alt, since it is not used in this keyboard layout :)

@picnixz picnixz added needs backport to 3.13 and removed 3.13 bugs and security fixes 3.14 bugs and security fixes labels Apr 12, 2025
@chris-eibl

Copy link
Copy Markdown
Member Author

The failing of Ubuntu (free-threading) is definitely unrelated, since this is a Windows specific change.

@tomasr8

tomasr8 commented Apr 17, 2025

Copy link
Copy Markdown
Member

Do you think it'd be possible to add some tests for this change to ensure we don't accidentally regress again?

@chris-eibl

Copy link
Copy Markdown
Member Author

Yeah, I've already thought about it, but am still unsure how to best do it.

ATM, I am thinking of mocking

def _read_input(self, block: bool = True) -> INPUT_RECORD | None:

to be able to test
def get_event(self, block: bool = True) -> Event | None:
"""Return an Event instance. Returns None if |block| is false
and there is no event pending, otherwise waits for the
completion of an event."""
while self.event_queue.empty():
rec = self._read_input(block)

AFAICT, all the existing tests just mock get_event, but for this, IMHO get_event itself must be tested.
Mocking _read_input seems to be the best way forward.

WDYT?

@tomasr8

tomasr8 commented Apr 17, 2025

Copy link
Copy Markdown
Member

Agreed that we shouldn't be mocking get_event since that's where we're making changes. _read_input seems like a good option, we can capture some real inputs and then replay them with it.

47 hidden items Load more…
@ambv ambv changed the title GH-132439: REPL on Windows swallows characters entered via AltGr May 5, 2025

@ambv ambv left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Hide comment

Excellent work again! Very well thought through.

@ambv ambv merged commit 07f416a into python:main May 5, 2025
@miss-islington-app

Copy link
Copy Markdown

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

@miss-islington-app

Copy link
Copy Markdown

Sorry, @chris-eibl and @ambv, I could not cleanly backport this to 3.13 due to a conflict.
Please backport using cherry_picker on command line.

cherry_picker 07f416a3f063db6b91b8b99ff61a51b64b0503f1 3.13

@ambv ambv changed the title GH-132439: Fix REPL swallowing characters entered with AltGr May 5, 2025
@sergey-miryanov

Copy link
Copy Markdown
Contributor

Will repeat here too - problem with backport because VT support was not backported #130805 (comment) (for completeness)

@ambv

ambv commented May 5, 2025

Copy link
Copy Markdown
Contributor

Yeah, I am backporting the VT support too because it's the only way we can have a sensibly similar codebase for bug fixes.

ambv pushed a commit to ambv/cpython that referenced this pull request May 5, 2025
…ltGr on cmd.exe (pythonGH-132440)

(cherry picked from commit 07f416a)

Co-authored-by: Chris Eibl <138194463+chris-eibl@users.noreply.github.com>
Co-authored-by: Stan Ulbrych <89152624+StanFromIreland@users.noreply.github.com>
@bedevere-app

bedevere-app Bot commented May 5, 2025

Copy link
Copy Markdown

GH-133460 is a backport of this pull request to the 3.13 branch.

@bedevere-app bedevere-app Bot removed the needs backport to 3.13 bugs and security fixes label May 5, 2025
ambv added a commit that referenced this pull request May 5, 2025
…n cmd.exe (GH-132440) (GH-133460)

(cherry picked from commit 07f416a)

Co-authored-by: Chris Eibl <138194463+chris-eibl@users.noreply.github.com>
Co-authored-by: Stan Ulbrych <89152624+StanFromIreland@users.noreply.github.com>
@chris-eibl chris-eibl deleted the fix_altgr branch May 5, 2025 18:14
Pranjal095 pushed a commit to Pranjal095/cpython that referenced this pull request Jul 12, 2025
… cmd.exe (pythonGH-132440)

Co-authored-by: Stan Ulbrych <89152624+StanFromIreland@users.noreply.github.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

OS-windows topic-repl Related to the interactive shell

Projects

None yet

Development

Successfully merging this pull request may close these issues.

6 participants