Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions Lib/idlelib/News3.txt
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,11 @@ Released on 2026-10-01
=========================


gh-85320: IDLE now reads and writes its configuration files and the
breakpoints file using UTF-8 instead of the locale encoding.
Comment thread
serhiy-storchaka marked this conversation as resolved.
Files with non-ASCII characters and non-UTF-8 encoding may need
to be opened in an editor and resaved with UTF-8 encoding.

gh-143774: Better explain the operation of Format / Format Paragraph.
Patch by Terry J. Reedy.

Expand Down
9 changes: 5 additions & 4 deletions Lib/idlelib/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -73,8 +73,9 @@ def GetOptionList(self, section):

def Load(self):
"Load the configuration file from disk."
if self.file:
self.read(self.file)
if self.file and os.path.exists(self.file):
with open(self.file, encoding='utf-8', errors='replace') as f:
self.read_file(f)

class IdleUserConfParser(IdleConfParser):
"""
Expand Down Expand Up @@ -133,10 +134,10 @@ def Save(self):
if fname and fname[0] != '#':
if not self.IsEmpty():
try:
cfgFile = open(fname, 'w')
cfgFile = open(fname, 'w', encoding='utf-8')
except OSError:
os.unlink(fname)
cfgFile = open(fname, 'w')
cfgFile = open(fname, 'w', encoding='utf-8')
with cfgFile:
self.write(cfgFile)
elif os.path.exists(self.file):
Expand Down
8 changes: 5 additions & 3 deletions Lib/idlelib/pyshell.py
Original file line number Diff line number Diff line change
Expand Up @@ -242,12 +242,13 @@ def store_file_breaks(self):
breaks = self.breakpoints
filename = self.io.filename
try:
with open(self.breakpointPath) as fp:
with open(self.breakpointPath,
encoding='utf-8', errors='replace') as fp:
lines = fp.readlines()
except OSError:
lines = []
try:
with open(self.breakpointPath, "w") as new_file:
with open(self.breakpointPath, "w", encoding='utf-8') as new_file:
for line in lines:
if not line.startswith(filename + '='):
new_file.write(line)
Expand All @@ -272,7 +273,8 @@ def restore_file_breaks(self):
if filename is None:
return
if os.path.isfile(self.breakpointPath):
with open(self.breakpointPath) as fp:
with open(self.breakpointPath,
encoding='utf-8', errors='replace') as fp:
lines = fp.readlines()
for line in lines:
if line.startswith(filename + '='):
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
IDLE now reads and writes its configuration files and the breakpoints file
using UTF-8 instead of the locale encoding. This keeps non-ASCII data (such
as non-ASCII paths) from being corrupted and makes the files portable between
environments.
Loading