python / python/cpython

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

Aperta
#153,480 2 commenti 0 reazioni 0 assegnatari Vedi su GitHub

Nessuno ha ancora preso questa issue.

3.13 3.14 3.15 stdlib topic-IDLE type-bug type-crash
Lingua principale
Python
Stelle
77.2k
Fork
35.9k
Metriche di merge delle PR
Metriche PR in attesa

Descrizione

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

Guida per i contributori

Apri la guida per i contributori

Come iniziare

  1. Leggi tutta la issue e poi la guida ai contributi del progetto.
  2. Commenta sulla issue per dire che te ne occupi tu — evita che due persone facciano lo stesso lavoro.
  3. Fai un fork del repository e lavora su un branch.
  4. Apri una pull request che faccia riferimento al numero della issue.

Direzione di ricerca

Inizia in idlelib.editor, su EditorWindow.last_mtime e sul suo chiamante, focus_in_event. Riproduci il caso di file mancante dell’issue, quindi verifica che riportare il focus su IDLE non sollevi più un’eccezione e che il controllo del ricaricamento non richieda conferma per un file eliminato.

Scritto dal modello di indicizzazione a partire dal testo della issue.

Valutazione

Stack tecnologico
python
Ambito
desktop
Tipo di issue
Bug
Difficoltà
2/5
Tempo stimato
1-3 ore
Stato di attività
Ferma
Chiarezza
Specificata chiaramente
Idoneità per principianti
25/100

Ricevi le nuove issue nella tua casella

Un breve riepilogo di issue GitHub adatte ai principianti.