Skip to content

gh-140824: Implement the math package in Python#141363

Closed
vstinner wants to merge 12 commits into
python:mainfrom
vstinner:_math
Closed

gh-140824: Implement the math package in Python#141363
vstinner wants to merge 12 commits into
python:mainfrom
vstinner:_math

Conversation

@vstinner
Copy link
Copy Markdown
Member

@vstinner vstinner commented Nov 10, 2025

Rename the 'math' extension to '_math'.

Rename the 'math' extension to '_math'.
Comment thread Modules/Setup Outdated
Comment thread Modules/Setup.stdlib.in Outdated
Comment thread configure.ac Outdated
Comment thread Lib/math/__init__.py
Comment thread Lib/math/__init__.py
Comment on lines +7 to +8
# gh-140824: Fix module name for pickle
def patch_module(objs, module):
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Would it be better just to have the module name as math.integer for these functions in C?

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In C, function.__module__ is set to the extension name: so set to _math or _math_integer. The whole purpose of this PR is to fix function.__module__.

@bedevere-app
Copy link
Copy Markdown

bedevere-app Bot commented Nov 10, 2025

When you're done making the requested changes, leave the comment: I have made the requested changes; please review again.

@vstinner vstinner requested a review from a team as a code owner November 10, 2025 16:16
Comment thread Lib/test/test_math.py Outdated
vstinner and others added 4 commits November 10, 2025 17:19
Co-authored-by: Adam Turner <9087854+AA-Turner@users.noreply.github.com>
@vstinner
Copy link
Copy Markdown
Member Author

@AA-Turner: I addressed your review. Please review the updated PR.

Copy link
Copy Markdown
Member

@serhiy-storchaka serhiy-storchaka left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is still a hack. I think there should be more straightforward way.

Comment thread Lib/math/__init__.py Outdated
@skirpichev skirpichev self-requested a review November 10, 2025 22:35
Comment thread Lib/math/__init__.py
Comment on lines +17 to +18
from _math_integer import comb, factorial, gcd, isqrt, lcm, perm
patch_module([comb, factorial, gcd, isqrt, lcm, perm], 'math.integer')
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe then instead:

import _math_integer
patch_module(_math_integer, 'math.integer')

where in the patch_module() you will fix all public names in the submodule namespace?

This still be a hack, but at least we can factor out patch_module() to some helper function, that can be used when a new submodule will be added to the stdlib.

@serhiy-storchaka
Copy link
Copy Markdown
Member

I believe there is a way to do this without hacks.

@vstinner
Copy link
Copy Markdown
Member Author

@serhiy-storchaka dislikes this approach, so I prefer to close my PR.

@vstinner vstinner closed this Jan 22, 2026
@vstinner vstinner deleted the _math branch January 22, 2026 11:05
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants