gh-127495: Append to history file after every statement in PyREPL (GH-132294)

This commit is contained in:
Sergey B Kirpichev 2025-04-27 16:32:37 +03:00 committed by GitHub
parent 614d79231d
commit 276252565c
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
4 changed files with 47 additions and 1 deletions

View file

@ -30,8 +30,9 @@ import functools
import os
import sys
import code
import warnings
from .readline import _get_reader, multiline_input
from .readline import _get_reader, multiline_input, append_history_file
_error: tuple[type[Exception], ...] | type[Exception]
@ -144,6 +145,10 @@ def run_multiline_interactive_console(
input_name = f"<python-input-{input_n}>"
more = console.push(_strip_final_indent(statement), filename=input_name, _symbol="single") # type: ignore[call-arg]
assert not more
try:
append_history_file()
except (FileNotFoundError, PermissionError, OSError) as e:
warnings.warn(f"failed to open the history file for writing: {e}")
input_n += 1
except KeyboardInterrupt:
r = _get_reader()