Make _Nothing a singleton (#433)

* Make _Nothing a singleton

* Satisfy linter

* Correct rst syntax
This commit is contained in:
Gabe Appleton 2018-08-27 04:58:24 -07:00 committed by Hynek Schlawack
parent 746f047a27
commit 4a83c93c05
1 changed files with 6 additions and 14 deletions

View File

@ -47,27 +47,19 @@ class _Nothing(object):
"""
Sentinel class to indicate the lack of a value when ``None`` is ambiguous.
All instances of `_Nothing` are equal.
``_Nothing`` is a singleton. There is only ever one of it.
"""
def __copy__(self):
return self
_singleton = None
def __deepcopy__(self, _):
return self
def __eq__(self, other):
return other.__class__ == _Nothing
def __ne__(self, other):
return not self == other
def __new__(cls):
if _Nothing._singleton is None:
_Nothing._singleton = super(_Nothing, cls).__new__(cls)
return _Nothing._singleton
def __repr__(self):
return "NOTHING"
def __hash__(self):
return 0xc0ffee
NOTHING = _Nothing()
"""