diff options
author | Eric Wieser <wieser.eric@gmail.com> | 2018-02-03 12:04:46 -0800 |
---|---|---|
committer | Eric Wieser <wieser.eric@gmail.com> | 2018-02-03 20:44:55 -0800 |
commit | 1271e17ea6ca8abe12f7dd045ac0af8674f594d4 (patch) | |
tree | e91980324d59b95b0f698de3f8a2d9f9fa7a9c45 /numpy/_globals.py | |
parent | 2854d508d1c6d211f2ce99e8747eda1cb427a78a (diff) | |
download | numpy-1271e17ea6ca8abe12f7dd045ac0af8674f594d4.tar.gz |
ENH: Add a repr to np._NoValue
This change _NoValue from a class to an instance, which is more inline with the builtin None.
Fixes gh-8991, closes gh-9592
Diffstat (limited to 'numpy/_globals.py')
-rw-r--r-- | numpy/_globals.py | 24 |
1 files changed, 19 insertions, 5 deletions
diff --git a/numpy/_globals.py b/numpy/_globals.py index 2d7b69bc4..9a7b458f1 100644 --- a/numpy/_globals.py +++ b/numpy/_globals.py @@ -52,11 +52,25 @@ class VisibleDeprecationWarning(UserWarning): """ pass - -class _NoValue(object): +class _NoValueType(object): """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. + The instance of 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 + __instance = None + def __new__(cls): + # ensure that only one instance exists + if not cls.__instance: + cls.__instance = super(_NoValueType, cls).__new__(cls) + return cls.__instance + + # needed for python 2 to preserve identity through a pickle + def __reduce__(self): + return (self.__class__, ()) + + def __repr__(self): + return "<no value>" + +_NoValue = _NoValueType() |