[3.13] gh-122273: Support PyREPL history on Windows (#127141) (#127289)

gh-122273: Support PyREPL history on Windows (#127141)

Co-authored-by: devdanzin <74280297+devdanzin@users.noreply.github.com>
(cherry picked from commit 3c7a90a831)
This commit is contained in:
Victor Stinner 2024-11-26 12:17:13 +01:00 committed by GitHub
parent 9187ac3f2d
commit a5741d63bc
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
3 changed files with 40 additions and 20 deletions

View file

@ -450,7 +450,9 @@ class _ReadlineWrapper:
def write_history_file(self, filename: str = gethistoryfile()) -> None:
maxlength = self.saved_history_length
history = self.get_reader().get_trimmed_history(maxlength)
with open(os.path.expanduser(filename), "w", encoding="utf-8") as f:
f = open(os.path.expanduser(filename), "w",
encoding="utf-8", newline="\n")
with f:
for entry in history:
entry = entry.replace("\n", "\r\n") # multiline history support
f.write(entry + "\n")