-
-
Notifications
You must be signed in to change notification settings - Fork 34.5k
Make the math module an extension package #140824
Copy link
Copy link
Open
Labels
3.15new features, bugs and security fixesnew features, bugs and security fixesbuildThe build process and cross-buildThe build process and cross-buildextension-modulesC modules in the Modules dirC modules in the Modules dirtype-featureA feature request or enhancementA feature request or enhancement
Metadata
Metadata
Assignees
Labels
3.15new features, bugs and security fixesnew features, bugs and security fixesbuildThe build process and cross-buildThe build process and cross-buildextension-modulesC modules in the Modules dirC modules in the Modules dirtype-featureA feature request or enhancementA feature request or enhancement
In #81313 a new module
math.integerwas added. It was implemented as the_math_integerextension module, modified to look like amathsubmodule. This required assigning theintegerattribute of themathmodule, settingsys.modules['math.integer'], patching the__name__attribute of the new module and the__module__attribute of its functions (to support help and pickling). Still, some implementation details are visible:sys.modules['_math_integer'], the__spec__attribute of the new module. Also, it is difficult to stop importing themath.integermodule automatically when themathmodule is imported.Import machinery in principle supports extension packages and extension submodules, but there is no precedence of this in the stdlib, and it is not trivial to build them. The
mathmodule should be compiled intomath/__init__.*.soinstead ofmath.*.so, andmath.integercorrespondingly intomath/integer.*.so. I believe this is possible.Linked PRs