python / python/cpython

IDLE fails to start or raises when an editor window's file does not exist

オープン
#153,480 コメント 2 件 リアクション 0 件 担当者 0 名 GitHub で見る

まだ誰も着手していません。

3.13 3.14 3.15 stdlib topic-IDLE type-bug type-crash
主要言語
Python
スター
77.2k
フォーク
35.9k
PR マージ指標
PR 指標を取得中

説明

Bug report

Bug description:

IDLE raises an uncaught traceback when a file that is open in the editor is deleted or renamed by another program and the IDLE window is then refocused.

EditorWindow.focus_in_event runs on every <FocusIn> event and calls EditorWindow.last_mtime, which calls os.path.getmtime(self.io.filename) with no error handling. When the open file has been removed or renamed, getmtime raises FileNotFoundError, which escapes the Tk event handler and breaks the modified-on-disk reload check.

Reproduction

Open a file in the IDLE editor, delete or rename it in another program, then click back into the IDLE window. A traceback like this reaches the console and the reload check stops working:

FileNotFoundError: [Errno 2] No such file or directory: '.../somefile.py'

The same call reproduced without a GUI:

import os, tempfile, types
from idlelib.editor import EditorWindow

with tempfile.TemporaryDirectory() as d:
    path = os.path.join(d, 'gone.py')
    open(path, 'w').close()
    mtime = os.path.getmtime(path)
    os.remove(path)
    stub = types.SimpleNamespace(io=types.SimpleNamespace(filename=path), mtime=mtime)
    EditorWindow.last_mtime(stub)   # raises FileNotFoundError on the main branch

Suggested fix

Guard os.path.getmtime in last_mtime with try/except OSError and return the last known mtime, so focus_in_event sees no change and does not prompt to reload a file that is gone.

CPython versions tested on:

3.16, CPython main branch

Operating systems tested on:

macOS

Linked PRs
  • gh-153481

コントリビューションガイド

コントリビューションガイドを開く

はじめの一歩

  1. issue を最後まで読み、次にプロジェクトのコントリビューションガイドを読みます。
  2. 着手することを issue にコメントします — 二人が同じ作業をするのを防げます。
  3. リポジトリをフォークし、ブランチを切って変更します。
  4. issue 番号を参照したプルリクエストを送ります。

調査の方向性

idlelib.editor の EditorWindow.last_mtime と、その呼び出し元である focus_in_event から始めます。issue にあるファイル欠落のケースを再現し、その後、IDLE に再びフォーカスを移しても例外が発生しないこと、またリロードチェックで削除されたファイルについて確認を求められないことを確認します。

索引モデルが issue の本文から書いたものです。

評価

技術スタック
python
領域
desktop
issue の種類
バグ
難易度
2/5
見積もり時間
1〜3時間
活発さ
停滞
明瞭さ
明確に書かれている
初心者へのやさしさ
25/100

新しい issue をメールで受け取る

初心者向けの GitHub issue を短くまとめたダイジェスト。