From a908ac6f93bfdfc057c91b4d470ea86e86d18741 Mon Sep 17 00:00:00 2001 From: Dzmitry Plashchynski Date: Tue, 15 Jul 2025 10:44:31 +0300 Subject: [PATCH] gh-131189: Fix "msvcrt" import warning on Linux when "_ctypes" is not available. (GH-131201) Fix "msvcrt" import warning on Linux when "_ctypes" is not available. On Linux, compiling without "libffi" causes a "No module named 'msvcrt'" warning when launching PyREPL. (cherry picked from commit f320c951c3220aa6727b581216463e8b3f8bcd6b) Co-authored-by: Dzmitry Plashchynski --- Lib/_pyrepl/readline.py | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/Lib/_pyrepl/readline.py b/Lib/_pyrepl/readline.py index be229488e54e37..f802a9526909e7 100644 --- a/Lib/_pyrepl/readline.py +++ b/Lib/_pyrepl/readline.py @@ -42,10 +42,11 @@ Console: type[ConsoleType] _error: tuple[type[Exception], ...] | type[Exception] -try: - from .unix_console import UnixConsole as Console, _error -except ImportError: + +if os.name == "nt": from .windows_console import WindowsConsole as Console, _error +else: + from .unix_console import UnixConsole as Console, _error ENCODING = sys.getdefaultencoding() or "latin1"