summaryrefslogtreecommitdiff
path: root/numpy/tests/test_public_api.py
diff options
context:
space:
mode:
authorSebastian Berg <sebastianb@nvidia.com>2022-12-05 18:14:25 +0100
committerSebastian Berg <sebastianb@nvidia.com>2022-12-06 12:00:21 +0100
commit928a7b40a40941c0c282cfad78c3a6021422a71c (patch)
tree09baf0ae86a0f1be479e4a2ba2b088f633bbc942 /numpy/tests/test_public_api.py
parent297c66131f2a32ebb7dfb0aeb9d88d917a791430 (diff)
downloadnumpy-928a7b40a40941c0c282cfad78c3a6021422a71c.tar.gz
API: Hide exceptions from the main namespace
I wasn't sure if we should already start deprecating the exceptions so opted to follow up with only hiding them from `__dir__()` but still having them in `__all__` and available. This also changes their module to `numpy.exceptions`, which matters because that is how they will be pickled (it would not be possible to unpickle such an exception in an older NumPy version). Due to pickling, we could put off changing the module.
Diffstat (limited to 'numpy/tests/test_public_api.py')
-rw-r--r--numpy/tests/test_public_api.py14
1 files changed, 14 insertions, 0 deletions
diff --git a/numpy/tests/test_public_api.py b/numpy/tests/test_public_api.py
index 28ed2f1df..c41639043 100644
--- a/numpy/tests/test_public_api.py
+++ b/numpy/tests/test_public_api.py
@@ -505,3 +505,17 @@ def test_array_api_entry_point():
"does not point to our Array API implementation"
)
assert xp is numpy.array_api, msg
+
+
+@pytest.mark.parametrize("name", [
+ 'ModuleDeprecationWarning', 'VisibleDeprecationWarning',
+ 'ComplexWarning', 'TooHardError', 'AxisError'])
+def test_moved_exceptions(name):
+ # These were moved to the exceptions namespace, but currently still
+ # available
+ assert name in np.__all__
+ assert name not in np.__dir__()
+ # Fetching works, but __module__ is set correctly:
+ assert getattr(np, name).__module__ == "numpy.exceptions"
+ assert name in np.exceptions.__all__
+ getattr(np.exceptions, name)