From 40a9a9a48afba58ba1fe3968d4bce7f13a2ff64e Mon Sep 17 00:00:00 2001 From: Eduardo Villalpando Mello Date: Thu, 10 Sep 2026 10:13:34 -0700 Subject: [PATCH 1/2] PyREPL: Don't register hooks twice --- python_files/pythonrc.py | 21 +++++++------------- python_files/tests/test_shell_integration.py | 4 ++-- 2 files changed, 9 insertions(+), 16 deletions(-) diff --git a/python_files/pythonrc.py b/python_files/pythonrc.py index 32498a60e624..ff6f7806ef06 100644 --- a/python_files/pythonrc.py +++ b/python_files/pythonrc.py @@ -29,19 +29,17 @@ def __init__(self): self.failure_flag = False self.original_excepthook = sys.excepthook self.original_displayhook = sys.displayhook - sys.excepthook = self.my_excepthook - sys.displayhook = self.my_displayhook + sys.excepthook = self.vscode_excepthook + sys.displayhook = self.vscode_displayhook - def my_displayhook(self, value): + def vscode_displayhook(self, value): if value is None: self.failure_flag = False - self.original_displayhook(value) - def my_excepthook(self, type_, value, traceback): + def vscode_excepthook(self, type_, value, traceback): self.global_exit = value self.failure_flag = True - self.original_excepthook(type_, value, traceback) @@ -50,15 +48,11 @@ def get_last_command(): last_command = "" if sys.platform != "win32": last_command = readline.get_history_item(readline.get_current_history_length()) - return last_command class PS1: hooks = REPLHooks() - sys.excepthook = hooks.my_excepthook - sys.displayhook = hooks.my_displayhook - # str will get called for every prompt with exit code to show success/failure def __str__(self): exit_code = int(bool(self.hooks.failure_flag)) @@ -101,7 +95,6 @@ def __repr__(self): if sys.platform != "win32" and (not is_wsl): sys.ps1 = PS1() -if sys.platform == "darwin": - print("Cmd click to launch VS Code Native REPL (https://aka.ms/python-native-repl)") -else: - print("Ctrl click to launch VS Code Native REPL (https://aka.ms/python-native-repl)") +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)") diff --git a/python_files/tests/test_shell_integration.py b/python_files/tests/test_shell_integration.py index 013aa3d514b5..f1750b3853d4 100644 --- a/python_files/tests/test_shell_integration.py +++ b/python_files/tests/test_shell_integration.py @@ -46,7 +46,7 @@ def test_displayhook_call(): hooks = pythonrc.REPLHooks() hooks.original_displayhook = mock_displayhook - hooks.my_displayhook("mock_value") + hooks.vscode_displayhook("mock_value") mock_displayhook.assert_called_once_with("mock_value") @@ -59,7 +59,7 @@ def test_excepthook_call(): hooks = pythonrc.REPLHooks() hooks.original_excepthook = mock_excepthook - hooks.my_excepthook("mock_type", "mock_value", "mock_traceback") + hooks.vscode_excepthook("mock_type", "mock_value", "mock_traceback") mock_excepthook.assert_called_once_with("mock_type", "mock_value", "mock_traceback") From 945831c5e9f725f4807e1df6bc67c2a17045066f Mon Sep 17 00:00:00 2001 From: Eduardo Villalpando Mello Date: Thu, 10 Sep 2026 10:18:38 -0700 Subject: [PATCH 2/2] Lint --- python_files/pythonrc.py | 1 + 1 file changed, 1 insertion(+) diff --git a/python_files/pythonrc.py b/python_files/pythonrc.py index ff6f7806ef06..182fea98a2c9 100644 --- a/python_files/pythonrc.py +++ b/python_files/pythonrc.py @@ -53,6 +53,7 @@ def get_last_command(): class PS1: hooks = REPLHooks() + # str will get called for every prompt with exit code to show success/failure def __str__(self): exit_code = int(bool(self.hooks.failure_flag))