python / python/cpython

Split Up _testsinglephase.c and _testmultiphase.c

未关闭
#124,983 2 条评论 0 个 reaction 已指派 0 人 在 GitHub 查看

还没有人认领这个 Issue。

extension-modules tests type-refactor
主要语言
Python
星标
77.2k
派生
35.9k
PR 合并指标
PR 指标待抓取

描述

(low priority)

Modules/_testsinglephase.c and Modules/_testmultiphase.c both contain the implementations of multiple modules. We should consider splitting up both files, so each contained module has its own file.

Here are several reasons why this may be worth doing:

  • testing with a module hidden in another's .so file is awkward and makes those tests harder to understand
  • it's easier to accidentally leak C-module global data between modules when they are implemented in the same file
  • when adding a new module, it's trickier (less familiar) to implement it in an existing file than in a new file [^1]

[^1]: However, adding it to an existing file is also simpler in how adding a new file involves tweaking the build. See the devguide.

Furthermore, both files were added to test specific import functionality. As far as I can tell[^2], that never included any need for the multiple-modules-in-one-file approach. However, currently they are the only place where we're testing the feature, regardless of how unintentionally or superficially. gh-124978 targets fixing that lack of explicit testing, including moving away from _testsinglephase.c and _testmultiphase.c (e.g. using the dedicated Modules/_testimportmultiple.c).

[^2]: I personally added Modules/_testsinglephase.c and @encukou added _testmultiphase.c.

All that said, splitting up the files is a fairly low priority task. The status quo isn't ideal but it isn't that bad either.


Here's how I see us taking care of this:

  1. make sure multiple-modules-in-one-file is tested via the dedicated Modules/_testimportmultiple.c [^2] (see gh-124978)
  2. create the Modules/_testsinglephase directory
  3. move each module from _testsinglephase.c to its own file (see the devguide)
  4. update the relevant tests
  5. delete Modules/_testsinglephase.c
  6. repeat steps 2-5 for Modules/_testmultiphase.c

贡献指南

打开贡献指南

从这里开始

  1. 先读完整个 Issue,再读项目的贡献指南。
  2. 在 Issue 下留言说明你要接手 —— 这能避免两个人做同样的事。
  3. Fork 仓库,在一个分支上完成修改。
  4. 提交 Pull Request,并在描述里引用这个 Issue 编号。

调研方向

首先查看 Modules/_testsinglephase.c 和 Modules/_testmultiphase.c、相关测试以及 gh-124978,然后按照 devguide 的 extension-module 工作流程进行。完成的标准是:明确覆盖多模块行为,每个包含的模块都有自己的文件,相关测试已更新,并且两个原始文件都已删除。

由索引模型根据 Issue 内容生成。

评估

技术栈
c
领域
build-system, testing
Issue 类型
重构
难度
4/5
预计耗时
3-5 天
活跃度
停滞
描述清晰度
基本清楚
新手友好度
45/100

把新 issue 发到你的邮箱

精选适合新手参与的 GitHub issue 摘要。