summaryrefslogtreecommitdiff
path: root/numpy/__init__.py
diff options
context:
space:
mode:
authorCharles Harris <charlesr.harris@gmail.com>2016-07-20 11:09:36 -0600
committerCharles Harris <charlesr.harris@gmail.com>2016-08-16 13:12:32 -0600
commit0ade4c43f052247a2d12a2c49d3c846e6c429fa9 (patch)
tree9a392681beeb6e1b297e8563867068fb5fa1106d /numpy/__init__.py
parent63d30baee2535f03d55a10819ea1e56165d4c030 (diff)
downloadnumpy-0ade4c43f052247a2d12a2c49d3c846e6c429fa9.tar.gz
BUG: Make sure numpy globals keep identity after reload.
Reloading currently causes problems because global classes defined in numpy/__init__.py change their identity (a is b) after reload. The solution taken here is to move those classes to a new non-reloadable module numpy/_globals and import them into numpy from there. Classes moved are ModuleDeprecationWarning, VisibleDeprecationWarning, and _NoValue. Closes #7844.
Diffstat (limited to 'numpy/__init__.py')
-rw-r--r--numpy/__init__.py58
1 files changed, 8 insertions, 50 deletions
diff --git a/numpy/__init__.py b/numpy/__init__.py
index 4be750c19..5384d61ab 100644
--- a/numpy/__init__.py
+++ b/numpy/__init__.py
@@ -109,56 +109,8 @@ from __future__ import division, absolute_import, print_function
import sys
import warnings
-# Disallow reloading numpy. Doing that does nothing to change previously
-# loaded modules, which would need to be reloaded separately, but it does
-# change the identity of the warnings and sentinal classes defined below
-# with dire consequences when checking for identity.
-if '_is_loaded' in globals():
- raise RuntimeError('Reloading numpy is not supported')
-_is_loaded = True
-
-
-# Define some global warnings and the _NoValue sentinal. Defining them here
-# means that their identity will change if numpy is reloaded, hence if that is
-# to be allowed they should be moved into their own, non-reloadable module.
-# Note that these should be defined (or imported) before the other imports.
-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.
-
- """
- pass
-
-
-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.
-
- """
- pass
-
-
-class _NoValue:
- """Special keyword value.
-
- This class may be used as the default value assigned to a deprecated
- keyword in order to check if it has been given a user defined value.
- """
- pass
-
-
-# oldnumeric and numarray were removed in 1.9. In case some packages import
-# but do not use them, we define them here for backward compatibility.
-oldnumeric = 'removed'
-numarray = 'removed'
-
+from ._globals import ModuleDeprecationWarning, VisibleDeprecationWarning
+from ._globals import _NoValue
# We first need to detect if we're being called as part of the numpy setup
# procedure itself in a reliable manner.
@@ -177,6 +129,7 @@ else:
its source directory; please exit the numpy source tree, and relaunch
your python interpreter from there."""
raise ImportError(msg)
+
from .version import git_revision as __git_revision__
from .version import version as __version__
@@ -239,3 +192,8 @@ else:
warnings.filterwarnings("ignore", message="numpy.dtype size changed")
warnings.filterwarnings("ignore", message="numpy.ufunc size changed")
warnings.filterwarnings("ignore", message="numpy.ndarray size changed")
+
+ # oldnumeric and numarray were removed in 1.9. In case some packages import
+ # but do not use them, we define them here for backward compatibility.
+ oldnumeric = 'removed'
+ numarray = 'removed'