]> git.ipfire.org Git - thirdparty/Python/cpython.git/commitdiff
gh-128066: Properly handle history file writes for RO fs on PyREPL (gh-134380)
authorChris Patti <feoh@feoh.org>
Tue, 20 May 2025 19:47:57 +0000 (15:47 -0400)
committerGitHub <noreply@github.com>
Tue, 20 May 2025 19:47:57 +0000 (21:47 +0200)
Co-authored-by: Ɓukasz Langa <lukasz@langa.pl>
Lib/_pyrepl/simple_interact.py
Lib/site.py
Misc/NEWS.d/next/Core_and_Builtins/2025-05-20-14-41-50.gh-issue-128066.qzzGfv.rst [new file with mode: 0644]

index c23894a34b8b53a25585fc957fed95c8efa95b5b..965b853c34b392e61a821de820d1ba074e074287 100644 (file)
@@ -31,6 +31,7 @@ import os
 import sys
 import code
 import warnings
+import errno
 
 from .readline import _get_reader, multiline_input, append_history_file
 
@@ -153,6 +154,7 @@ def run_multiline_interactive_console(
                 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()
index 5c38b1b17d5abdaaea1185c534798ee1ff6c91d1..f93271971594d8310377a0c92ad1c93ab24226f7 100644 (file)
@@ -75,6 +75,7 @@ import builtins
 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 (file)
index 0000000..f781902
--- /dev/null
@@ -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.