Skip to content

gh-153480: Stop IDLE crashing when a file open in the editor is deleted#153481

Open
tonghuaroot wants to merge 1 commit into
python:mainfrom
tonghuaroot:idlelib-editor-last-mtime-oserror
Open

gh-153480: Stop IDLE crashing when a file open in the editor is deleted#153481
tonghuaroot wants to merge 1 commit into
python:mainfrom
tonghuaroot:idlelib-editor-last-mtime-oserror

Conversation

@tonghuaroot

@tonghuaroot tonghuaroot commented Jul 10, 2026

Copy link
Copy Markdown
Contributor

EditorWindow.focus_in_event runs on every <FocusIn> event and calls last_mtime, which called os.path.getmtime(self.io.filename) with no error handling. When the open file had been deleted or renamed by another program, refocusing the editor window let a FileNotFoundError escape the Tk event handler and broke the modified-on-disk reload check.

last_mtime now guards getmtime with try/except OSError and returns the last known mtime, so focus_in_event sees no change and does not prompt to reload a file that is gone. The regression test drives last_mtime as an unbound method against a duck-typed stub (no GUI) for both the deleted-file and no-filename cases.

… deleted

EditorWindow.focus_in_event calls last_mtime on every <FocusIn> event,
which passed the open file path to os.path.getmtime with no guard. When
another program deleted or renamed the file, refocusing the IDLE window
let a FileNotFoundError escape the Tk event handler. last_mtime now
returns the last known mtime when the path is inaccessible, so refocusing
no longer raises and does not prompt to reload a file that is gone.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant