summaryrefslogtreecommitdiff
path: root/numpy
diff options
context:
space:
mode:
authorSebastian Berg <sebastianb@nvidia.com>2022-11-22 12:27:54 +0100
committerSebastian Berg <sebastianb@nvidia.com>2022-11-30 12:07:51 +0100
commit1d31511ce8081f03ac507854c94cf4793a5982e3 (patch)
treeb00a734afed7417c37cb14c6d7c20676a65f930c /numpy
parentb0f318b38e7dd305c3ca93e6c912e1391dda999e (diff)
downloadnumpy-1d31511ce8081f03ac507854c94cf4793a5982e3.tar.gz
MAINT: Move ModuleDeprecationWarning and ModuleDeprecationWarning
Both should now live in the "exceptions" module.
Diffstat (limited to 'numpy')
-rw-r--r--numpy/__init__.py9
-rw-r--r--numpy/_globals.py28
-rw-r--r--numpy/exceptions.py39
3 files changed, 43 insertions, 33 deletions
diff --git a/numpy/__init__.py b/numpy/__init__.py
index 5af2ac847..1e41dc8bf 100644
--- a/numpy/__init__.py
+++ b/numpy/__init__.py
@@ -106,11 +106,10 @@ Exceptions to this rule are documented.
import sys
import warnings
-from ._globals import (
- ModuleDeprecationWarning, VisibleDeprecationWarning,
- _NoValue, _CopyMode
-)
-from .exceptions import ComplexWarning, TooHardError, AxisError
+from ._globals import _NoValue, _CopyMode
+from .exceptions import (
+ ComplexWarning, ModuleDeprecationWarning, VisibleDeprecationWarning,
+ TooHardError, AxisError)
# We first need to detect if we're being called as part of the numpy setup
# procedure itself in a reliable manner.
diff --git a/numpy/_globals.py b/numpy/_globals.py
index 555777167..416a20f5e 100644
--- a/numpy/_globals.py
+++ b/numpy/_globals.py
@@ -19,10 +19,7 @@ import enum
from ._utils import set_module as _set_module
-__all__ = [
- 'ModuleDeprecationWarning', 'VisibleDeprecationWarning',
- '_NoValue', '_CopyMode'
- ]
+__all__ = ['_NoValue', '_CopyMode']
# Disallow reloading this module so as to preserve the identities of the
@@ -32,29 +29,6 @@ if '_is_loaded' in globals():
_is_loaded = True
-@_set_module("numpy")
-class ModuleDeprecationWarning(DeprecationWarning):
- """Module deprecation warning.
-
- The nose tester turns ordinary Deprecation warnings into test failures.
- That makes it hard to deprecate whole modules, because they get
- imported by default. So this is a special Deprecation warning that the
- nose tester will let pass without making tests fail.
-
- """
-
-
-@_set_module("numpy")
-class VisibleDeprecationWarning(UserWarning):
- """Visible deprecation warning.
-
- By default, python will not show deprecation warnings, so this class
- can be used when a very visible warning is helpful, for example because
- the usage is most likely a user bug.
-
- """
-
-
class _NoValueType:
"""Special keyword value.
diff --git a/numpy/exceptions.py b/numpy/exceptions.py
index 4a63263a5..6af5d52a1 100644
--- a/numpy/exceptions.py
+++ b/numpy/exceptions.py
@@ -1,6 +1,20 @@
from ._utils import set_module as _set_module
-__all__ = ["ComplexWarning", "TooHardError", "AxisError"]
+__all__ = [
+ "ComplexWarning", "ModuleDeprecationWarning", "VisibleDeprecationWarning",
+ "TooHardError", "AxisError"]
+
+
+# Disallow reloading this module so as to preserve the identities of the
+# classes defined here.
+if '_is_loaded' in globals():
+ raise RuntimeError('Reloading numpy._globals is not allowed')
+_is_loaded = True
+
+
+# TODO: One day, we should remove the _set_module here before removing them
+# fully. Not doing it now, just to allow unpickling to work on older
+# versions for a bit. (Module exists since NumPy 1.25.)
@_set_module('numpy')
@@ -16,6 +30,29 @@ class ComplexWarning(RuntimeWarning):
+@_set_module("numpy")
+class ModuleDeprecationWarning(DeprecationWarning):
+ """Module deprecation warning.
+
+ The nose tester turns ordinary Deprecation warnings into test failures.
+ That makes it hard to deprecate whole modules, because they get
+ imported by default. So this is a special Deprecation warning that the
+ nose tester will let pass without making tests fail.
+
+ """
+
+
+@_set_module("numpy")
+class VisibleDeprecationWarning(UserWarning):
+ """Visible deprecation warning.
+
+ By default, python will not show deprecation warnings, so this class
+ can be used when a very visible warning is helpful, for example because
+ the usage is most likely a user bug.
+
+ """
+
+
# Exception used in shares_memory()
@_set_module('numpy')
class TooHardError(RuntimeError):