Implement PEP 793 – PyModExport
还没有人认领这个 Issue。
- 主要语言
- Python
- 星标
- 77.2k
- 派生
- 36k
- PR 合并指标
- PR 指标待抓取
描述
Feature or enhancement
Proposal:
See PEP 793. I'll copy the abstract for reference:
In this PEP, we propose a new entry point for C extension modules, by which one can define a module using an array of
PyModuleDef_Slotstructures without an enclosingPyModuleDefstructure. This allows extension authors to avoid using a statically allocatedPyObject, lifting the most common obstacle to making one compiled library file usable with both regular and free-threaded builds of CPython.To make this viable, we also specify new module slot types to replace
PyModuleDef’s fields, and to allow adding a token similar to thePy_tp_tokenused for type objects.We also add an API for defining modules from slots dynamically.
The existing API (
PyInit_*) is soft-deprecated. (That is: it will continue to work without warnings, and it’ll be fully documented and supported, but we plan to not add any new features to it.)
- Initial implementation (#140556)
- Docs:
- Reference docs (#141197)
- Soft-deprecate
PyInit_*(#141197) - Better explanation of module state (#141197)
- Give an example for tokens (#141197)
- Soft-deprecate
- What's New
-
a notice for(edit: This shouldn't have changed/broken more than usual.)DYNLOADFILEusers?
-
- Porting guide HOWTO
- Document that the export hook runs without GIL in FT builds (see
#141780) (#151661)
- Document that the export hook runs without GIL in FT builds (see
- Tutorial update (#142314)
- Mentions in
PyImport_AppendInittab& friends (#151661) - Make sure references to new API are linked:
-
PyMod_ExecinPyImport_CreateModuleFromInitfuncdocs is linked (#141197) -
PyMODEXPORT_FUNCin blurb for#141672 -
blurb for#141780
-
- Reference docs (#141197)
-
xxlimited.cupdate (#142827)- Remove/replace
_Py_OPAQUE_PYOBJECTinxxlimited.c(by 3.15.0 beta)
- Remove/replace
Optional stretch goals:
- Remove the
PyInitfunction fromLib/test/test_cext/extension.c(https://github.com/python/cpython/pull/141511) - Speed & size improvements
-
importdl: load the DLL once -
boolfor the GIL flag (#141519)
-
- No longer require
spec.nameinPyModule_FromSlotsAndSpec - No longer require static allocation for
Py_mod_methods - Add a
PyModule_GetStateWithToken()function
Has this already been discussed elsewhere?
No response given
Links to previous discussion of this feature:
No response
Linked PRs
- gh-140556
- gh-141056
- gh-141197
- gh-141511
- gh-141519
- gh-142583
- gh-142827
- gh-144340
- gh-149397
- gh-149785
- gh-151661
- gh-152064
- gh-157493
- gh-157494
- gh-157539
- gh-157560
See also:
- gh-141672
- gh-142314
贡献指南
从这里开始
- 先读完整个 Issue,再读项目的贡献指南。
- 在 Issue 下留言说明你要接手 —— 这能避免两个人做同样的事。
- Fork 仓库,在一个分支上完成修改。
- 提交 Pull Request,并在描述里引用这个 Issue 编号。
调研方向
审查 PEP 793 提案以及尚未勾选的 stretch goal,尤其是 Lib/test/test_cext/extension.c 和 importdl 项。先检查链接的实现和文档工作,然后确定一个具体的剩余目标及其现有的测试或入口点;当该目标已实现并由相关文档或测试覆盖时,即视为完成。
由索引模型根据 Issue 内容生成。
评估
- 技术栈
- c, python
- 领域
- backend-api-design
- Issue 类型
- 功能
- 难度
- 5/5
- 预计耗时
- 一周以上
- 活跃度
- 停滞
- 描述清晰度
- 需要澄清
- 新手友好度
- 20/100