[issue44386] importlib and math.pi interact strangely

2021-06-13 Thread Ned Deily


Change by Ned Deily :


--
resolution:  -> not a bug
stage:  -> resolved
status: open -> closed

___
Python tracker 

___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue44386] importlib and math.pi interact strangely

2021-06-10 Thread Jack DeVries


Jack DeVries  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 

___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue44386] importlib and math.pi interact strangely

2021-06-10 Thread Paul Prescod


New submission from Paul Prescod :

from importlib import util

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

=

$ python3.8 /tmp/foo.py 
3.141592653589793

$ python3.9 /tmp/foo.py 
Traceback (most recent call last):
  File "/tmp/foo.py", line 5, in 
print(math1.pi)
AttributeError: module 'math' has no attribute 'pi'

--
components: Extension Modules
files: foo.py
messages: 395583
nosy: prescod2
priority: normal
severity: normal
status: open
title: importlib and math.pi interact strangely
versions: Python 3.10, Python 3.11
Added file: https://bugs.python.org/file50101/foo.py

___
Python tracker 

___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com