This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

Author jack__d
Recipients jack__d, prescod2
Date 2021-06-11.00:59:06
SpamBayes Score -1.0
Marked as misclassified Yes
Message-id <1623373147.28.0.729395600982.issue44386@roundup.psfhosted.org>
In-reply-to
Content
That is because pi, along with other constants in the math module are defined during module execution, not module creation:

https://github.com/python/cpython/blob/62f1d2b3d7dda99598d053e10b785c463fdcf591/Modules/cmathmodule.c#L1257-L1262

Taking the example right here (https://docs.python.org/3/library/importlib.html#checking-if-a-module-can-be-imported) from the docs, you can see how they call exec_module() after module_from_spec.

If you change your code to do that as well, you will find that pi is now defined:

========

from importlib import util

mathmodule = util.find_spec("math")
math1 = util.module_from_spec(mathmodule)
mathmodule.loader.exec_module(math1)
print(math1.pi)

========
History
Date User Action Args
2021-06-11 00:59:07jack__dsetrecipients: + jack__d, prescod2
2021-06-11 00:59:07jack__dsetmessageid: <1623373147.28.0.729395600982.issue44386@roundup.psfhosted.org>
2021-06-11 00:59:07jack__dlinkissue44386 messages
2021-06-11 00:59:06jack__dcreate