diff options
author | Charles Harris <charlesr.harris@gmail.com> | 2016-08-20 16:45:05 -0500 |
---|---|---|
committer | GitHub <noreply@github.com> | 2016-08-20 16:45:05 -0500 |
commit | 276423aa7f4f7d39189ee5ccf7b167ad2c9c25a7 (patch) | |
tree | b8f223f8ca798517c5b094271b2670e39415babe /numpy/_globals.py | |
parent | 86960c27cfe48346944ce3c5861740d36040bde2 (diff) | |
parent | 0ade4c43f052247a2d12a2c49d3c846e6c429fa9 (diff) | |
download | numpy-276423aa7f4f7d39189ee5ccf7b167ad2c9c25a7.tar.gz |
Merge pull request #7941 from charris/fix-numpy-reload-again
BUG: Make sure numpy globals keep identity after reload.
Diffstat (limited to 'numpy/_globals.py')
-rw-r--r-- | numpy/_globals.py | 62 |
1 files changed, 62 insertions, 0 deletions
diff --git a/numpy/_globals.py b/numpy/_globals.py new file mode 100644 index 000000000..64a84da96 --- /dev/null +++ b/numpy/_globals.py @@ -0,0 +1,62 @@ +""" +Module defining global singleton classes. + +This module raises a RuntimeError if an attempt to reload it is made. In that +way the identities of the classes defined here are fixed and will remain so +even if numpy itself is reloaded. In particular, a function like the following +will still work correctly after numpy is reloaded:: + + def foo(arg=np._NoValue): + if arg is np._NoValue: + ... + +That was not the case when the singleton classes were defined in the numpy +``__init__.py`` file. See gh-7844 for a discussion of the reload problem that +motivated this module. + +""" +from __future__ import division, absolute_import, print_function + + +__ALL__ = [ + 'ModuleDeprecationWarning', 'VisibleDeprecationWarning', '_NoValue' + ] + + +# 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 + + +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 |