IDLE fails to start or raises when an editor window's file does not exist
Ninguém assumiu esta issue ainda.
- Linguagem predominante
- Python
- Estrelas
- 77.2k
- Forks
- 36k
- Métricas de merge de PRs
- Métricas de PR pendentes
Descrição
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
Guia de contribuição
Primeiros passos
- Leia a issue inteira e depois o guia de contribuição do projeto.
- Comente na issue dizendo que vai assumir — evita que duas pessoas façam o mesmo trabalho.
- Faça um fork do repositório e trabalhe em uma branch.
- Abra um pull request que referencie o número da issue.
Direção de pesquisa
Comece em idlelib.editor, em EditorWindow.last_mtime e em seu chamador, focus_in_event. Reproduza o caso de arquivo ausente da issue e, em seguida, verifique se voltar a focar o IDLE não gera mais uma exceção e se a verificação de recarregamento não solicita confirmação para um arquivo excluído.
Escrita pelo modelo de indexação a partir do texto da issue.
Avaliação
- Stack de tecnologia
- python
- Domínio
- desktop
- Tipo de issue
- Bug
- Dificuldade
- 2/5
- Tempo estimado
- 1-3 horas
- Status de atividade
- Estagnada
- Clareza
- Claramente especificada
- Facilidade para iniciantes
- 25/100