https://github.com/python/cpython/commit/6e2272d0b199d1ab992fffac5fc8e356d7342aec
commit: 6e2272d0b199d1ab992fffac5fc8e356d7342aec
branch: main
author: Shixian Li <[email protected]>
committer: gpshead <[email protected]>
date: 2026-04-11T14:36:59-07:00
summary:
gh-94523: IDLE: Detect file if modified and prompt the user to refresh
(GH-145625)
files:
A Misc/NEWS.d/next/IDLE/2026-03-07-20-47-40.gh-issue-94523.dq7m2k.rst
M Lib/idlelib/editor.py
diff --git a/Lib/idlelib/editor.py b/Lib/idlelib/editor.py
index 3128934763a1c0..932b6bf70ac9fc 100644
--- a/Lib/idlelib/editor.py
+++ b/Lib/idlelib/editor.py
@@ -312,6 +312,9 @@ def __init__(self, flist=None, filename=None, key=None,
root=None):
else:
self.update_menu_state('options', '*ine*umbers', 'disabled')
+ self.mtime = self.last_mtime()
+ text_frame.bind('<FocusIn>', self.focus_in_event)
+
def handle_winconfig(self, event=None):
self.set_width()
@@ -1027,6 +1030,8 @@ def get_saved(self):
def set_saved(self, flag):
self.undo.set_saved(flag)
+ if flag:
+ self.mtime = self.last_mtime()
def reset_undo(self):
self.undo.reset_undo()
@@ -1112,6 +1117,21 @@ def _close(self):
# unless override: unregister from flist, terminate if last window
self.close_hook()
+ def last_mtime(self):
+ file = self.io.filename
+ return os.path.getmtime(file) if file else 0
+
+ def focus_in_event(self, event):
+ mtime = self.last_mtime()
+ if self.mtime != mtime:
+ self.mtime = mtime
+ if self. askyesno(
+ 'Reload', '"%s"\n\nThis script has been modified by another
program.'
+ '\nDo you want to reload it?' % self.io.filename,
parent=self.text):
+ self.io.loadfile(self.io.filename)
+ else:
+ self.set_saved(False)
+
def load_extensions(self):
self.extensions = {}
self.load_standard_extensions()
diff --git
a/Misc/NEWS.d/next/IDLE/2026-03-07-20-47-40.gh-issue-94523.dq7m2k.rst
b/Misc/NEWS.d/next/IDLE/2026-03-07-20-47-40.gh-issue-94523.dq7m2k.rst
new file mode 100644
index 00000000000000..831f6ac628768c
--- /dev/null
+++ b/Misc/NEWS.d/next/IDLE/2026-03-07-20-47-40.gh-issue-94523.dq7m2k.rst
@@ -0,0 +1,2 @@
+Detect file if modified at local disk and prompt to ask refresh. Patch by
+Shixian Li.
_______________________________________________
Python-checkins mailing list -- [email protected]
To unsubscribe send an email to [email protected]
https://mail.python.org/mailman3//lists/python-checkins.python.org
Member address: [email protected]