python / python/cpython

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

未關閉
#149,013 0 則留言 0 個 reaction 已指派 0 人 在 GitHub 檢視

還沒有人認領這個 Issue。

3.15 tests topic-lazy-imports type-feature
主要語言
Python
星號
77.2k
分支
35.9k
PR 合併指標
PR 指標待擷取

描述

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

貢獻指南

開啟貢獻指南

從這裡開始

  1. 先讀完整個 Issue,再讀專案的貢獻指南。
  2. 在 Issue 下留言說明你要接手 —— 這能避免兩個人做同樣的事。
  3. Fork 儲存庫,在一個分支上完成修改。
  4. 送出 Pull Request,並在描述裡引用這個 Issue 編號。

研究方向

從 Lib/test/test_lazy_import/init.py 開始,閱讀現有的 lazy-import 覆蓋範圍與相關 helper。先執行 test_lazy_import 測試,然後為 reification 後的 reload() 以及刪除 sys.modules[name] 後的重新匯入新增覆蓋。完成的標準是 binding 與快取的 module 保持所述的 identity 行為,而刪除項目後的重新匯入會建立新的快取 module。

由索引模型根據 Issue 內容生成。

評估

技術堆疊
python
領域
testing-qa
Issue 類型
缺陷
難度
2/5
預估耗時
1-3 小時
活躍度
停滯
描述清晰度
描述清楚
新手友好度
35/100

把新 issue 寄到你的電子郵件信箱

精選適合新手參與的 GitHub issue 摘要。