107
107
from __future__ import division , absolute_import , print_function
108
108
109
109
import sys
110
+ import warnings
110
111
112
+ # Disallow reloading numpy. Doing that does nothing to change previously
113
+ # loaded modules, which would need to be reloaded separately, but it does
114
+ # change the identity of the warnings and sentinal classes defined below
115
+ # with dire consequences when checking for identity.
116
+ if '_is_loaded' in globals ():
117
+ raise RuntimeError ('Reloading numpy is not supported' )
118
+ _is_loaded = True
111
119
120
+
121
+ # Define some global warnings and the _NoValue sentinal. Defining them here
122
+ # means that their identity will change if numpy is reloaded, hence if that is
123
+ # to be allowed they should be moved into their own, non-reloadable module.
124
+ # Note that these should be defined (or imported) before the other imports.
112
125
class ModuleDeprecationWarning (DeprecationWarning ):
113
126
"""Module deprecation warning.
114
127
@@ -135,9 +148,8 @@ class VisibleDeprecationWarning(UserWarning):
135
148
class _NoValue :
136
149
"""Special keyword value.
137
150
138
- This class may be used as the default value assigned to a
139
- deprecated keyword in order to check if it has been given a user
140
- defined
8000
value.
151
+ This class may be used as the default value assigned to a deprecated
152
+ keyword in order to check if it has been given a user defined value.
141
153
"""
142
154
pass
143
155
@@ -155,11 +167,8 @@ class _NoValue:
155
167
except NameError :
156
168
__NUMPY_SETUP__ = False
157
169
158
-
159
170
if __NUMPY_SETUP__ :
160
- import sys as _sys
161
- _sys .stderr .write ('Running from numpy source directory.\n ' )
162
- del _sys
171
+ sys .stderr .write ('Running from numpy source directory.\n ' )
163
172
else :
164
173
try :
165
174
from numpy .__config__ import show as show_config
@@ -206,7 +215,7 @@ def pkgload(*packages, **options):
206
215
from .compat import long
207
216
208
217
# Make these accessible from numpy name-space
209
- # but not imported in from numpy import *
218
+ # but not imported in from numpy import *
210
219
if sys .version_info [0 ] >= 3 :
211
220
from builtins import bool , int , float , complex , object , str
212
221
unicode = str
@@ -222,8 +231,8 @@ def pkgload(*packages, **options):
222
231
__all__ .extend (lib .__all__ )
223
232
__all__ .extend (['linalg' , 'fft' , 'random' , 'ctypeslib' , 'ma' ])
224
233
234
+
225
235
# Filter annoying Cython warnings that serve no good purpose.
226
- import warnings
227
236
warnings .filterwarnings ("ignore" , message = "numpy.dtype size changed" )
228
237
warnings .filterwarnings ("ignore" , message = "numpy.ufunc size changed" )
229
238
warnings .filterwarnings ("ignore" , message = "numpy.ndarray size changed" )
0 commit comments