From d0916b06124bea9608f0b3e6b71362f6b6616f05 Mon Sep 17 00:00:00 2001 From: Eduardo Villalpando Mello Date: Wed, 7 Oct 2026 10:41:47 -0700 Subject: [PATCH 1/2] PyREPL: Update Regex --- python_files/pythonrc.py | 14 ++++++++------ python_files/tests/test_shell_integration.py | 12 ++++++++++++ 2 files changed, 20 insertions(+), 6 deletions(-) diff --git a/python_files/pythonrc.py b/python_files/pythonrc.py index cb2d7f22f429..a9444ac5bf60 100644 --- a/python_files/pythonrc.py +++ b/python_files/pythonrc.py @@ -9,12 +9,13 @@ def _initialize(): if sys.version_info >= (3, 13): import re - import _pyrepl.simple_interact import _pyrepl.utils - _pyrepl.utils.ANSI_ESCAPE_SEQUENCE = re.compile( - r"\x1b(?:\[[ -@]*[A-~]|\][^\x1b\x07]*(?:\x07|\x1b\\))" - ) + _ansi_escape_sequence = re.compile(r"\x1b(?:\[[ -@]*[A-~]|\][^\x1b\x07]*(?:\x07|\x1b\\))") + _pyrepl.utils.ANSI_ESCAPE_SEQUENCE = _ansi_escape_sequence + + # Import again to ensure the module is loaded after patching the ANSI_ESCAPE_SEQUENCE + import _pyrepl.simple_interact # Patch _pyrepl.simple_interact.multiline_input to ensure prompts are strings _original_multiline_input = _pyrepl.simple_interact.multiline_input @@ -70,6 +71,7 @@ def execution_finished(cls, exit_code: int) -> str: @classmethod def command_line(cls, command: object) -> str: """Explicitly set the command line interpreted by the shell.""" + return "" return cls.template.format(f"E;{command}") class REPLHooks: @@ -136,12 +138,12 @@ def __repr__(self): return "" is_wsl = "microsoft-standard-WSL" in platform.release() - if not is_wsl and (sys.platform != "win32" or sys.version_info >= (3, 13)): + if True and (sys.platform != "win32" or sys.version_info >= (3, 13)): sys.ps1 = PS1() ctrl_key = "Cmd" if sys.platform == "darwin" else "Ctrl" - print(f"{ctrl_key} click to launch VS Code Native REPL (https://aka.ms/python-native-repl)") + print(f"{ctrl_key} click to launch VS Code Native REPL (https://aka.ms/python-native-repl) :-)") _initialize() diff --git a/python_files/tests/test_shell_integration.py b/python_files/tests/test_shell_integration.py index 49646e3e5cb3..a25672531696 100644 --- a/python_files/tests/test_shell_integration.py +++ b/python_files/tests/test_shell_integration.py @@ -115,6 +115,18 @@ def test_replacement_regex_preserves_csi_handling(): ) +def test_replacement_regex_is_imported_by_pyrepl_modules(): + if sys.version_info < (3, 15): + return + + pyrepl_reader = importlib.import_module("_pyrepl.reader") + pyrepl_render = importlib.import_module("_pyrepl.render") + + assert pyrepl_reader.ANSI_ESCAPE_SEQUENCE.sub("", "\x1b]633;A\x07>>> ") == ">>> " + assert pyrepl_render.ANSI_ESCAPE_SEQUENCE.sub("", "\x1b]633;A\x07>>> ") == ">>> " + assert pyrepl_render.RenderLine.from_rendered_text("\x1b]633;A\x07>>> ").width == 4 + + def test_pyrepl_multiline_input_converts_prompts_to_strings(monkeypatch): if sys.version_info < (3, 13): return From 90d5d16d4747c9ef52e0de61d754b55e13e57567 Mon Sep 17 00:00:00 2001 From: Eduardo Villalpando Mello Date: Wed, 7 Oct 2026 10:57:55 -0700 Subject: [PATCH 2/2] Revert testing changes --- python_files/pythonrc.py | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/python_files/pythonrc.py b/python_files/pythonrc.py index a9444ac5bf60..d016cba4f5c5 100644 --- a/python_files/pythonrc.py +++ b/python_files/pythonrc.py @@ -71,7 +71,6 @@ def execution_finished(cls, exit_code: int) -> str: @classmethod def command_line(cls, command: object) -> str: """Explicitly set the command line interpreted by the shell.""" - return "" return cls.template.format(f"E;{command}") class REPLHooks: @@ -138,12 +137,12 @@ def __repr__(self): return "" is_wsl = "microsoft-standard-WSL" in platform.release() - if True and (sys.platform != "win32" or sys.version_info >= (3, 13)): + if not is_wsl and (sys.platform != "win32" or sys.version_info >= (3, 13)): sys.ps1 = PS1() ctrl_key = "Cmd" if sys.platform == "darwin" else "Ctrl" - print(f"{ctrl_key} click to launch VS Code Native REPL (https://aka.ms/python-native-repl) :-)") + print(f"{ctrl_key} click to launch VS Code Native REPL (https://aka.ms/python-native-repl)") _initialize()