[3.13] gh-119102: Fix REPL for dumb terminal (GH-119332) (#119359)

The site module gets the __main__ module to get _pyrepl.__main__.
(cherry picked from commit de8f530841)

Co-authored-by: Victor Stinner <vstinner@python.org>
This commit is contained in:
Miss Islington (bot) 2024-05-22 02:14:44 +02:00 committed by GitHub
parent 05820164ce
commit f371565169
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
1 changed files with 6 additions and 1 deletions

View 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)