Jack DeVries <jdevries3...@gmail.com> added the comment:

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)

========

----------
nosy: +jack__d

_______________________________________
Python tracker <rep...@bugs.python.org>
<https://bugs.python.org/issue44386>
_______________________________________
_______________________________________________
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com

Reply via email to