BUG: numpy.testing now depends on numpy.distutils
See original GitHub issueDescribe the issue:
As of numpy 1.22.0, specifically after 1b5b5871c725a5b67b55d29c7361a353d8ae13ef, import numpy.testing
implicitly imports numpy.distutils
. The exact line that introduced this is https://github.com/numpy/numpy/commit/84e0707afa587e7655410561324ac36085db2b95#diff-657b0df76a18e77d5033e7a763d2e40a58498dee25374a90c4db9850ce2f75d3R13 which appears to load an extension module building helper (utilising numpy.distutils
) into the numpy.testing
namespace. This is unfortunate because, despite numpy’s own usages of numpy.testing
being avoided except when testing, downstream projects do still use it. For example import scipy
imports numpy.testing
(somewhat unnecessarily IMO but I’ll make that case on their issue tracker) which now drags in numpy.distutils
.
Reproduce the code example:
# Attempt to load numpy.testing after blocking imports of `numpy.distutils`.
import sys
sys.modules["numpy.distutils"] = None
import numpy.testing
# Alternatively, you can skip the sys.modules blocking and just run:
import numpy.testing
assert "numpy.distutils" not in sys.modules
# But the first provides a traceback which indicates where the import leak is.
Error message:
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "/home/brenainn/.local/lib/python3.9/site-packages/numpy/testing/__init__.py", line 12, in <module>
from ._private import extbuild, decorators as dec
File "/home/brenainn/.local/lib/python3.9/site-packages/numpy/testing/_private/extbuild.py", line 11, in <module>
from numpy.distutils.ccompiler import new_compiler
ModuleNotFoundError: No module named 'numpy.distutils.ccompiler'; 'numpy.distutils' is not a package
NumPy/Python version information:
1.22.0 3.9.6 (default, Jul 30 2021, 22:48:59)
[GCC 11.1.0]
This is specific to numpy 1.22.0
. Earlier versions of numpy did not do this.
Note to whoever addresses this: If this is fixed after #20745 is merged then this conditional statement may be made unconditional.
Issue Analytics
- State:
- Created 2 years ago
- Comments:10 (10 by maintainers)
OK, PR inbound…
This also ‘breaks’ downstream test suites that use
np.testing
in Python 3.10 due to #20225, if they happen to do-Werror
.