test_lazy_import: add coverage for reload() and sys.modules deletion after reification
还没有人认领这个 Issue。
- 主要语言
- 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:
importlib.reload()on a module that was first imported lazily and then reified.- 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
贡献指南
从这里开始
- 先读完整个 Issue,再读项目的贡献指南。
- 在 Issue 下留言说明你要接手 —— 这能避免两个人做同样的事。
- Fork 仓库,在一个分支上完成修改。
- 提交 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