From 1271e17ea6ca8abe12f7dd045ac0af8674f594d4 Mon Sep 17 00:00:00 2001 From: Eric Wieser Date: Sat, 3 Feb 2018 12:04:46 -0800 Subject: 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 --- numpy/_globals.py | 24 +++++++++++++++++++----- 1 file changed, 19 insertions(+), 5 deletions(-) (limited to 'numpy/_globals.py') 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 "" + +_NoValue = _NoValueType() -- cgit v1.2.1