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
分支
36k
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 摘要。