https://github.com/python/cpython/commit/7c98b0674daa3e4eb3e8f35afb61a0dba61d1780
commit: 7c98b0674daa3e4eb3e8f35afb61a0dba61d1780
branch: main
author: Sergey Miryanov <[email protected]>
committer: pablogsal <[email protected]>
date: 2025-03-10T22:13:50Z
summary:
gh-130804: Fix support of typing unicode chars in pyrepl (#130805)
files:
A
Misc/NEWS.d/next/Core_and_Builtins/2025-03-10-21-46-37.gh-issue-130804.0PpcTx.rst
M Lib/_pyrepl/base_eventqueue.py
M Lib/test/test_pyrepl/test_eventqueue.py
diff --git a/Lib/_pyrepl/base_eventqueue.py b/Lib/_pyrepl/base_eventqueue.py
index 9cae1db112a838..e018c4fc18308e 100644
--- a/Lib/_pyrepl/base_eventqueue.py
+++ b/Lib/_pyrepl/base_eventqueue.py
@@ -69,13 +69,19 @@ def insert(self, event: Event) -> None:
trace('added event {event}', event=event)
self.events.append(event)
- def push(self, char: int | bytes) -> None:
+ def push(self, char: int | bytes | str) -> None:
"""
Processes a character by updating the buffer and handling special key
mappings.
"""
ord_char = char if isinstance(char, int) else ord(char)
- char = bytes(bytearray((ord_char,)))
- self.buf.append(ord_char)
+ if ord_char > 255:
+ assert isinstance(char, str)
+ char = bytes(char.encode(self.encoding, "replace"))
+ self.buf.extend(char)
+ else:
+ char = bytes(bytearray((ord_char,)))
+ self.buf.append(ord_char)
+
if char in self.keymap:
if self.keymap is self.compiled_keymap:
# sanity check, buffer is empty when a special key comes
diff --git a/Lib/test/test_pyrepl/test_eventqueue.py
b/Lib/test/test_pyrepl/test_eventqueue.py
index a1bac38fbd43f5..b25bdb956b0d14 100644
--- a/Lib/test/test_pyrepl/test_eventqueue.py
+++ b/Lib/test/test_pyrepl/test_eventqueue.py
@@ -123,6 +123,13 @@ def test_push_unrecognized_escape_sequence(self):
self.assertEqual(eq.events[2].evt, "key")
self.assertEqual(eq.events[2].data, "Z")
+ def test_push_unicode_character(self):
+ eq = self.make_eventqueue()
+ eq.keymap = {}
+ eq.push("ч")
+ self.assertEqual(eq.events[0].evt, "key")
+ self.assertEqual(eq.events[0].data, "ч")
+
@unittest.skipIf(support.MS_WINDOWS, "No Unix event queue on Windows")
class TestUnixEventQueue(EventQueueTestBase, unittest.TestCase):
diff --git
a/Misc/NEWS.d/next/Core_and_Builtins/2025-03-10-21-46-37.gh-issue-130804.0PpcTx.rst
b/Misc/NEWS.d/next/Core_and_Builtins/2025-03-10-21-46-37.gh-issue-130804.0PpcTx.rst
new file mode 100644
index 00000000000000..37a9b83c858331
--- /dev/null
+++
b/Misc/NEWS.d/next/Core_and_Builtins/2025-03-10-21-46-37.gh-issue-130804.0PpcTx.rst
@@ -0,0 +1 @@
+Fix support of unicode characters on Windows in the new REPL.
_______________________________________________
Python-checkins mailing list -- [email protected]
To unsubscribe send an email to [email protected]
https://mail.python.org/mailman3/lists/python-checkins.python.org/
Member address: [email protected]