python / python/cpython

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

Đang mở
#153,480 2 bình luận 0 reaction 0 người được giao Xem trên GitHub

Chưa có ai nhận issue này.

3.13 3.14 3.15 stdlib topic-IDLE type-bug type-crash
Ngôn ngữ chính
Python
Star
77.2k
Fork
35.9k
Chỉ số merge pull request
Chỉ số pull request đang chờ

Mô tả

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

Hướng dẫn đóng góp

Mở hướng dẫn đóng góp

Bắt đầu từ đâu

  1. Đọc hết issue, rồi đọc hướng dẫn đóng góp của dự án.
  2. Bình luận trên issue rằng bạn sẽ nhận — tránh hai người làm cùng một việc.
  3. Fork repository và làm thay đổi trên một nhánh.
  4. Mở pull request có tham chiếu số hiệu của issue.

Hướng nghiên cứu

Bắt đầu trong idlelib.editor tại EditorWindow.last_mtime và hàm gọi nó, focus_in_event. Tái hiện trường hợp tệp bị thiếu trong issue, sau đó xác minh rằng việc đưa lại tiêu điểm cho IDLE không còn phát sinh ngoại lệ và kiểm tra tải lại không yêu cầu xác nhận đối với tệp đã bị xóa.

Do mô hình lập chỉ mục viết ra từ nội dung của issue.

Đánh giá

Công nghệ
python
Lĩnh vực
desktop
Loại issue
Lỗi
Độ khó
2/5
Thời gian dự kiến
1-3 giờ
Mức độ hoạt động
Đình trệ
Độ rõ ràng
Đặc tả rõ ràng
Mức phù hợp với người mới
25/100

Nhận issue mới trong hộp thư của bạn

Bản tóm tắt ngắn những issue GitHub phù hợp với người mới.