https://github.com/python/cpython/commit/379805d03c7e2b3a19484c8247fad8da86b5a157
commit: 379805d03c7e2b3a19484c8247fad8da86b5a157
branch: 3.14
author: Miss Islington (bot) <31488909+miss-isling...@users.noreply.github.com>
committer: ambv <luk...@langa.pl>
date: 2025-05-20T22:15:23+02:00
summary:

[3.14] gh-128066: Properly handle history file writes for RO fs on PyREPL 
(gh-134380) (gh-134385)

(cherry picked from commit c91ad5da9d92eac4718e4da8d53689c3cc24535e)

Co-authored-by: Chris Patti <f...@feoh.org>
Co-authored-by: Ɓukasz Langa <luk...@langa.pl>

files:
A 
Misc/NEWS.d/next/Core_and_Builtins/2025-05-20-14-41-50.gh-issue-128066.qzzGfv.rst
M Lib/_pyrepl/simple_interact.py
M Lib/site.py

diff --git a/Lib/_pyrepl/simple_interact.py b/Lib/_pyrepl/simple_interact.py
index c23894a34b8b53..965b853c34b392 100644
--- a/Lib/_pyrepl/simple_interact.py
+++ b/Lib/_pyrepl/simple_interact.py
@@ -31,6 +31,7 @@
 import sys
 import code
 import warnings
+import errno
 
 from .readline import _get_reader, multiline_input, append_history_file
 
@@ -153,6 +154,7 @@ def maybe_run_command(statement: str) -> bool:
                 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()
diff --git a/Lib/site.py b/Lib/site.py
index 5c38b1b17d5abd..f93271971594d8 100644
--- a/Lib/site.py
+++ b/Lib/site.py
@@ -75,6 +75,7 @@
 import _sitebuiltins
 import _io as io
 import stat
+import errno
 
 # Prefixes for site-packages; add additional prefixes like /usr/local here
 PREFIXES = [sys.prefix, sys.exec_prefix]
@@ -578,10 +579,15 @@ def register_readline():
         def write_history():
             try:
                 readline_module.write_history_file(history)
-            except (FileNotFoundError, PermissionError):
+            except FileNotFoundError, PermissionError:
                 # home directory does not exist or is not writable
                 # https://bugs.python.org/issue19891
                 pass
+            except OSError:
+                if errno.EROFS:
+                    pass  # gh-128066: read-only file system
+                else:
+                    raise
 
         atexit.register(write_history)
 
diff --git 
a/Misc/NEWS.d/next/Core_and_Builtins/2025-05-20-14-41-50.gh-issue-128066.qzzGfv.rst
 
b/Misc/NEWS.d/next/Core_and_Builtins/2025-05-20-14-41-50.gh-issue-128066.qzzGfv.rst
new file mode 100644
index 00000000000000..f78190276851b4
--- /dev/null
+++ 
b/Misc/NEWS.d/next/Core_and_Builtins/2025-05-20-14-41-50.gh-issue-128066.qzzGfv.rst
@@ -0,0 +1,3 @@
+Fixes an edge case where PyREPL improperly threw an error when Python is
+invoked on a read only filesystem while trying to write history file
+entries.

_______________________________________________
Python-checkins mailing list -- python-checkins@python.org
To unsubscribe send an email to python-checkins-le...@python.org
https://mail.python.org/mailman3/lists/python-checkins.python.org/
Member address: arch...@mail-archive.com

Reply via email to