GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — Make the math module an extension package · Issue #140824 · python/cpython

Make the math module an extension package #140824

New issue
Copy link
New issue
Copy link
Open
Open
Make the math module an extension package#140824
Copy link
Labels
3.15bugs and security fixesbugs 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

Description

@serhiy-storchaka
serhiy-storchaka
opened on Oct 31, 2025
Issue body actions

In #81313 a new module math.integer was added. It was implemented as the _math_integer extension module, modified to look like a math submodule. This required assigning the integer attribute of the math module, setting sys.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 the math.integer module automatically when the math module 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 math module should be compiled into math/__init__.*.so instead of math.*.so, and math.integer correspondingly into math/integer.*.so. I believe this is possible.

Linked PRs

  • gh-140824: Implement the math package in Python #141363
  • gh-140824: remove math.integer submodule name for sys.stdlib_module_names #144294
  • gh-140824: Fix _Py_DumpExtensionModules() to ignore sub-modules #144339
  • gh-140824: Build the math module as an extension package #152352
Reacted by Zachary Ware

Activity

  1. serhiy-storchaka
    added
    extension-modulesC modules in the Modules dirC modules in the Modules dir
    buildThe build process and cross-buildThe build process and cross-build
    3.15bugs and security fixesbugs and security fixes
    on Oct 31, 2025
  2. StanFromIreland
    added
    type-featureA feature request or enhancementA feature request or enhancement
    on Oct 31, 2025
  3. itamaro commented on Nov 9, 2025

    @itamaro
    itamaro
    on Nov 9, 2025
    Contributor
    More actions

    it might be simpler to convert the _math and _math_integer extensions to builtins. not sure it would actually solve what you want to solve though.

  4. vstinner
    added 2 commits that reference this issue on Nov 10, 2025

    pythongh-140824: _math extension

    42c2e06

    pythongh-140824: Implement the math package in Python

    9f5cc45
  5. vstinner commented on Nov 10, 2025

    @vstinner
    vstinner
    on Nov 10, 2025
    Member
    More actions

    it might be simpler to convert the _math and _math_integer extensions to builtins. not sure it would actually solve what you want to solve though.

    I don't think that converting these extensions to built-in extensions would solve the problem of functions __module__ set to the wrong module.

  6. vstinner commented on Nov 10, 2025

    @vstinner
    vstinner
    on Nov 10, 2025
    Member
    More actions

    I created #141363 to solve this problem: implement the math package in Python.

  7. vstinner commented on Nov 10, 2025

    @vstinner
    vstinner
    on Nov 10, 2025
    Member
    More actions

    cc @skirpichev

  8. skirpichev commented on Nov 11, 2025

    @skirpichev
    skirpichev
    on Nov 11, 2025
    Member
    More actions

    I created #141363 to solve this problem

    Sorry, I don't think it's a good alternative to the current hack. It's just a different hack.

    Reacted by Serhiy Storchaka
  9. vstinner commented on Jan 22, 2026

    @vstinner
    vstinner
    on Jan 22, 2026
    Member
    More actions

    math.integer is missing from sys.stdlib_module_names:

    >>> import sys
    >>> 'math.integer' in sys.stdlib_module_names
    False
    
  10. skirpichev
    added a commit that references this issue on Jan 28, 2026

    pythongh-140824: workaround math.integer module name for sys.stdlib_m…

    adc2bd0
  11. StanFromIreland commented on Jan 28, 2026

    @StanFromIreland
    StanFromIreland
    on Jan 28, 2026
    Member
    More actions

    math.integer is missing from sys.stdlib_module_names

    FTR, this is expected per the doc.

  12. vstinner commented on Jan 28, 2026

    @vstinner
    vstinner
    on Jan 28, 2026
    Member
    More actions

    math.integer is missing from sys.stdlib_module_names

    The problem is that the _Py_DumpExtensionModules() function considers that math.integer is not part of the stdlib. Example with faulthandler on a crash:

    $ ./python -X faulthandler
    >>> import math.integer
    >>> import ctypes
    >>> ctypes.string_at(0)
    Fatal Python error: Segmentation fault
    
    Current thread 0x00007f01b0b2a780 [python] (most recent call first):
      File "/home/vstinner/python/main/Lib/ctypes/__init__.py", line 607 in string_at
      ...
    
    Current thread's C stack trace (most recent call first):
      Binary file "./python", at _Py_DumpStack+0x31 [0x674654]
      ...
    
    Extension modules: math.integer (total: 1)
    

    FTR, this is expected per the doc.

    _Py_DumpExtensionModules() should be update to ignore math.integer.

  13. skirpichev commented on Jan 28, 2026

    @skirpichev
    skirpichev
    on Jan 28, 2026
    Member
    More actions

    _Py_DumpExtensionModules() should be update to ignore math.integer.

    This also will be solved, if we remove math.integer from sys.stdlib_module_names.

  14. vstinner
    added 2 commits that reference this issue on Jan 30, 2026

    pythongh-140824: Fix _Py_DumpExtensionModules() to ignore sub-modules

    b796179

    pythongh-140824: Fix _Py_DumpExtensionModules() to ignore sub-modules

    1445a8d
  15. vstinner commented on Jan 30, 2026

    @vstinner
    vstinner
    on Jan 30, 2026
    Member
    More actions

    I wrote a fix for _Py_DumpExtensionModules(): #144339 ignores math.integer since math is part of sys.stdlib_module_names.

  16. vstinner
    added a commit that references this issue on Feb 4, 2026

    gh-140824: Fix _Py_DumpExtensionModules() to ignore sub-modules (#144339

    2aea861
  17. encukou
    added a commit that references this issue on Feb 5, 2026

    pythongh-140824: Fix _Py_DumpExtensionModules() to ignore sub-modules (…

    3fd84ba
  18. thunder-coding
    added a commit that references this issue on Feb 15, 2026

    pythongh-140824: Fix _Py_DumpExtensionModules() to ignore sub-modules (…

    86b9531
  19. ljfp
    added a commit that references this issue on Apr 25, 2026

    pythongh-140824: Fix _Py_DumpExtensionModules() to ignore sub-modules (…

    b2932db
  20. serhiy-storchaka
    added a commit that references this issue on Jun 27, 2026

    pythongh-140824: Build the math module as an extension package

    9dc3148
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    3.15bugs and security fixesbugs 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

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions

      You are visitor 01402503 — GeezerVison does not store the pages you look up.
      Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.