python / python/cpython

test_lazy_import: add coverage for reload() and sys.modules deletion after reification

Đang mở
#149,013 0 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.15 tests topic-lazy-imports type-feature
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 / test coverage gap

Lib/test/test_lazy_import/__init__.py has broad lazy import coverage, but it misses two practical state-transition scenarios after reification:

  1. importlib.reload() on a module that was first imported lazily and then reified.
  2. Deleting sys.modules[name] after reification and then importing again.

Why this matters

These are common import-state operations and can regress subtly when lazy import behavior changes.
Adding tests helps lock in expected semantics and prevents regressions in future import machinery refactors.

Proposed change

Add two tests in test_lazy_import:

  • test_reload_after_lazy_reification_keeps_single_module_object

    • Reify a lazily imported module.
    • Call importlib.reload().
    • Assert identity consistency between the binding and sys.modules[name].
  • test_reimport_after_deleting_sys_modules_entry_creates_new_module

    • Reify a lazily imported module.
    • Delete sys.modules[name].
    • Verify old binding still works.
    • Re-import module and assert a new module object is cached.

Affected files

  • Lib/test/test_lazy_import/__init__.py

Version

  • main (3.15 development branch)

Additional notes

This is test-only; no runtime behavior change is introduced.

Linked PRs
  • gh-149014

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 Lib/test/test_lazy_import/init.py và đọc phần coverage hiện có cho lazy-import cùng các helper liên quan. Trước tiên, chạy các test test_lazy_import, sau đó bổ sung coverage cho reload() sau khi reification và cho việc re-import sau khi xóa sys.modules[name]. Hoàn tất khi binding và module được cache giữ nguyên hành vi identity đã nêu, trong khi việc re-import sau khi xóa entry tạo ra một module mới được cache.

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
testing-qa
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
35/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.