]> git.ipfire.org Git - thirdparty/Python/cpython.git/commitdiff
gh-119102: Fix REPL for dumb terminal (#119332)
authorVictor Stinner <vstinner@python.org>
Tue, 21 May 2024 20:33:52 +0000 (22:33 +0200)
committerGitHub <noreply@github.com>
Tue, 21 May 2024 20:33:52 +0000 (20:33 +0000)
The site module gets the __main__ module to get _pyrepl.__main__.

Lib/site.py

index 4ba078388a37b8ef7c3c401a4891efc9563cee2e..f1a6d9cf66fdc3ab15c0b5018f1218d036c51c43 100644 (file)
@@ -523,7 +523,12 @@ def register_readline():
             pass
 
         def write_history():
-            from _pyrepl.__main__ import CAN_USE_PYREPL
+            try:
+                # _pyrepl.__main__ is executed as the __main__ module
+                from __main__ import CAN_USE_PYREPL
+            except ImportError:
+                CAN_USE_PYREPL = False
+
             try:
                 if os.getenv("PYTHON_BASIC_REPL") or not CAN_USE_PYREPL:
                     readline.write_history_file(history)