Blame numpy/_globals.py

Packit 7a8e5e
"""
Packit 7a8e5e
Module defining global singleton classes.
Packit 7a8e5e
Packit 7a8e5e
This module raises a RuntimeError if an attempt to reload it is made. In that
Packit 7a8e5e
way the identities of the classes defined here are fixed and will remain so
Packit 7a8e5e
even if numpy itself is reloaded. In particular, a function like the following
Packit 7a8e5e
will still work correctly after numpy is reloaded::
Packit 7a8e5e
Packit 7a8e5e
    def foo(arg=np._NoValue):
Packit 7a8e5e
        if arg is np._NoValue:
Packit 7a8e5e
            ...
Packit 7a8e5e
Packit 7a8e5e
That was not the case when the singleton classes were defined in the numpy
Packit 7a8e5e
``__init__.py`` file. See gh-7844 for a discussion of the reload problem that
Packit 7a8e5e
motivated this module.
Packit 7a8e5e
Packit 7a8e5e
"""
Packit 7a8e5e
from __future__ import division, absolute_import, print_function
Packit 7a8e5e
Packit 7a8e5e
Packit 7a8e5e
__ALL__ = [
Packit 7a8e5e
    'ModuleDeprecationWarning', 'VisibleDeprecationWarning', '_NoValue'
Packit 7a8e5e
    ]
Packit 7a8e5e
Packit 7a8e5e
Packit 7a8e5e
# Disallow reloading this module so as to preserve the identities of the
Packit 7a8e5e
# classes defined here.
Packit 7a8e5e
if '_is_loaded' in globals():
Packit 7a8e5e
    raise RuntimeError('Reloading numpy._globals is not allowed')
Packit 7a8e5e
_is_loaded = True
Packit 7a8e5e
Packit 7a8e5e
Packit 7a8e5e
class ModuleDeprecationWarning(DeprecationWarning):
Packit 7a8e5e
    """Module deprecation warning.
Packit 7a8e5e
Packit 7a8e5e
    The nose tester turns ordinary Deprecation warnings into test failures.
Packit 7a8e5e
    That makes it hard to deprecate whole modules, because they get
Packit 7a8e5e
    imported by default. So this is a special Deprecation warning that the
Packit 7a8e5e
    nose tester will let pass without making tests fail.
Packit 7a8e5e
Packit 7a8e5e
    """
Packit 7a8e5e
    pass
Packit 7a8e5e
Packit 7a8e5e
Packit 7a8e5e
class VisibleDeprecationWarning(UserWarning):
Packit 7a8e5e
    """Visible deprecation warning.
Packit 7a8e5e
Packit 7a8e5e
    By default, python will not show deprecation warnings, so this class
Packit 7a8e5e
    can be used when a very visible warning is helpful, for example because
Packit 7a8e5e
    the usage is most likely a user bug.
Packit 7a8e5e
Packit 7a8e5e
    """
Packit 7a8e5e
    pass
Packit 7a8e5e
Packit 7a8e5e
Packit 7a8e5e
class _NoValue(object):
Packit 7a8e5e
    """Special keyword value.
Packit 7a8e5e
Packit 7a8e5e
    This class may be used as the default value assigned to a deprecated
Packit 7a8e5e
    keyword in order to check if it has been given a user defined value.
Packit 7a8e5e
    """
Packit 7a8e5e
    pass