Skip to content

Conversation

@serhiy-storchaka
Copy link
Member

@serhiy-storchaka serhiy-storchaka commented May 11, 2025

@serhiy-storchaka
Copy link
Member Author

This is a further development of #13741.

@vstinner
Copy link
Member

A PEP is being written for this module: skirpichev/peps#8

@vstinner

This comment was marked as resolved.

itamaro

This comment was marked as resolved.

skirpichev

This comment was marked as resolved.

@corona10

This comment was marked as resolved.

@skirpichev

This comment was marked as resolved.

@skirpichev skirpichev self-requested a review May 13, 2025 12:39
@skirpichev

This comment was marked as resolved.

@skirpichev skirpichev changed the title gh-81313: Add the imath module gh-81313: Add the intmath module Jun 1, 2025
@picnixz picnixz changed the title gh-81313: Add the intmath module gh-81313: Add the intmath module (PEP-791) Jun 1, 2025
Co-authored-by: Sergey B Kirpichev <skirpichev@gmail.com>
@serhiy-storchaka
Copy link
Member Author

Perhaps, module in Lib/ (which will import stuff from private C module) is better.

No, this would only make things worse. This would break the module name for math functions too.

The right solution is to compile the math module to math/__init__.cpython-315d-x86_64-linux-gnu.so instead of math.cpython-315d-x86_64-linux-gnu.so, but I was not able to find how to do this. I hope we will fix this in the following PR.

@serhiy-storchaka
Copy link
Member Author

I used other way to fix the module name. This is a temporary hack, I hope we will make it a straight way in future.

@skirpichev
Copy link
Contributor

I think test failures are relevant.

@vstinner
Copy link
Member

@vstinner, I worked on this several days ago, and here is the result. But there is a flaw in this implementation -- math.integer.name is not 'math.integer', and the module attribute of its functions is not 'math.integer'. This affects pickling and the help output.

IMO it's good enough for a first iteration, we will have enough time until Python 3.15 final to find a way to fix these issues.

…awSH.rst

Co-authored-by: Victor Stinner <vstinner@python.org>
Copy link
Contributor

@skirpichev skirpichev left a comment

Choose a reason for hiding this comment

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

Playing with the new module, I found also this:

>>> math.integer.__spec__
ModuleSpec(name='_math_integer', loader=<_frozen_importlib_external.ExtensionFileLoader object at 0x7fdbdae6f150>, origin='/home/sk/src/cpython/build/lib.linux-x86_64-3.15/_math_integer.cpython-315-x86_64-linux-gnu.so')

Comment on lines +723 to +724
For backward compatibility, the :mod:`math` module provides also aliases of
the following functions from the :mod:`math.integer` module:
Copy link
Contributor

Choose a reason for hiding this comment

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

Please mention there, that these aliases are soft-deprecated.

BTW, why this section was moved?

Copy link
Member Author

Choose a reason for hiding this comment

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

Because it is less important than other sections.

Copy link
Contributor

Choose a reason for hiding this comment

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

Maybe it is, if we want to communicate users this renaming. Though, it's important only for those who read docs in order... Up to you.

Comment on lines +1242 to +1244
/* Fix the __name__ attribute of the module and the __module__ attribute
* of its functions.
*/
Copy link
Contributor

Choose a reason for hiding this comment

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

Could you, please, create an issue to track this?

IIUIC, currently it's also not clear how to name the module file (math_integermodule.c, math/integermodule.c or even intmathmodule.c). I.e. we should extend current naming scheme to submodules.

Copy link
Member Author

Choose a reason for hiding this comment

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

See #140824.

serhiy-storchaka and others added 2 commits October 31, 2025 11:08
Co-authored-by: Sergey B Kirpichev <skirpichev@gmail.com>
Copy link
Contributor

@skirpichev skirpichev left a comment

Choose a reason for hiding this comment

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

LGTM, with few nitpicks (up to Serhiy) and note about ModuleSpec(). (I suspect this might affect something.)

Copy link
Member

@vstinner vstinner left a comment

Choose a reason for hiding this comment

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

LGTM

.. versionchanged:: 3.10
Floats with integral values (like ``5.0``) are no longer accepted in the
:func:`factorial` function.

Copy link
Member

Choose a reason for hiding this comment

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

Maybe add a versionchanged to mention that these functions became aliases to math.integer functions?

Copy link
Member Author

Choose a reason for hiding this comment

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

This did not change their behavior.

Floats with integral values (like ``5.0``) are no longer accepted in the
:func:`factorial` function.


Copy link
Member

Choose a reason for hiding this comment

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

You should add .. deprecated:: 3.15 to repeat that these functions are soft deprecated and math.integer functions should be used instead.

@serhiy-storchaka serhiy-storchaka merged commit dcf3cc5 into python:main Oct 31, 2025
54 checks passed
@serhiy-storchaka serhiy-storchaka deleted the imath3 branch October 31, 2025 14:13
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

7 participants