-
-
Notifications
You must be signed in to change notification settings - Fork 34k
gh-140824: Implement the math package in Python #141363
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
9f5cc45
f2650f7
a6430dc
f510afd
2d2afd6
d60e832
7cf0fc1
a20e9fb
2527857
aaeaee1
d366724
49e6b3a
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,20 @@ | ||
| """ | ||
| This module provides access to the mathematical functions | ||
| defined by the C standard. | ||
| """ | ||
|
|
||
| from _math import * | ||
|
|
||
| # gh-140824: Fix module name for pickle | ||
| def patch_module(objs, module): | ||
| for obj in objs: | ||
| if not hasattr(obj, "__module__"): | ||
| continue | ||
| obj.__module__ = module | ||
| patch_module([obj for name, obj in globals().items() | ||
| if not name.startswith('_')], 'math') | ||
|
|
||
| from _math_integer import comb, factorial, gcd, isqrt, lcm, perm | ||
| patch_module([comb, factorial, gcd, isqrt, lcm, perm], 'math.integer') | ||
|
Comment on lines
+17
to
+18
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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 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. |
||
|
|
||
| del patch_module | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,5 @@ | ||
| """ | ||
| This module provides access to integer related mathematical functions. | ||
| """ | ||
|
|
||
| from _math_integer import * |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
There was a problem hiding this comment.
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.integerfor these functions in C?There was a problem hiding this comment.
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_mathor_math_integer. The whole purpose of this PR is to fixfunction.__module__.