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 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
@@ -209,7 +218,7 @@ def pkgload(*packages, **options):
209
218
from .compat import long
210
219
211
220
# Make these accessible from numpy name-space
212
- # but not imported in from numpy import *
221
+ # but not imported in from numpy import *
213
222
if sys .version_info [0 ] >= 3 :
214
223
from builtins import bool , int , float , complex , object , str
215
224
unicode = str
@@ -225,8 +234,8 @@ def pkgload(*packages, **options):
225
234
__all__ .extend (lib .__all__ )
226
235
__all__ .extend (['linalg' , 'fft' , 'random' , 'ctypeslib' , 'ma' ])
227
236
237
+
228
238
# Filter annoying Cython warnings that serve no good purpose.
229
- import warnings
230
239
warnings .filterwarnings ("ignore" , message = "numpy.dtype size changed" )
231
240
warnings .filterwarnings ("ignore" , message = "numpy.ufunc size changed" )
232
241
warnings .filterwarnings ("ignore" , message = "numpy.ndarray size changed" )
0 commit comments