Skip to content

Commit 8ea0cfa

Browse files
committed
catch OSError in maybe_run_command() instead
1 parent 5dadcc4 commit 8ea0cfa

File tree

2 files changed

+5
-10
lines changed

2 files changed

+5
-10
lines changed

Lib/_pyrepl/readline.py

Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -464,14 +464,8 @@ def append_history_file(self, filename: str = gethistoryfile()) -> None:
464464
saved_length = self.get_history_length()
465465
length = self.get_current_history_length() - saved_length
466466
history = reader.get_trimmed_history(length)
467-
468-
try:
469-
f = open(os.path.expanduser(filename), "a",
470-
encoding="utf-8", newline="\n")
471-
except OSError as e:
472-
warnings.warn(f"failed to open the history file for writing: {e}")
473-
return
474-
467+
f = open(os.path.expanduser(filename), "a",
468+
encoding="utf-8", newline="\n")
475469
with f:
476470
for entry in history:
477471
entry = entry.replace("\n", "\r\n") # multiline history support

Lib/_pyrepl/simple_interact.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@
3030
import os
3131
import sys
3232
import code
33+
import warnings
3334

3435
from .readline import _get_reader, multiline_input, append_history_file
3536

@@ -143,8 +144,8 @@ def maybe_run_command(statement: str) -> bool:
143144

144145
try:
145146
append_history_file()
146-
except (FileNotFoundError, PermissionError):
147-
pass
147+
except (FileNotFoundError, PermissionError, OSError) as e:
148+
warnings.warn(f"failed to open the history file for writing: {e}")
148149
input_name = f"<python-input-{input_n}>"
149150
more = console.push(_strip_final_indent(statement), filename=input_name, _symbol="single") # type: ignore[call-arg]
150151
assert not more

0 commit comments

Comments
 (0)