Make _Nothing a singleton (#433)
* Make _Nothing a singleton * Satisfy linter * Correct rst syntax
This commit is contained in:
parent
746f047a27
commit
4a83c93c05
|
@ -47,27 +47,19 @@ class _Nothing(object):
|
||||||
"""
|
"""
|
||||||
Sentinel class to indicate the lack of a value when ``None`` is ambiguous.
|
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):
|
_singleton = None
|
||||||
return self
|
|
||||||
|
|
||||||
def __deepcopy__(self, _):
|
def __new__(cls):
|
||||||
return self
|
if _Nothing._singleton is None:
|
||||||
|
_Nothing._singleton = super(_Nothing, cls).__new__(cls)
|
||||||
def __eq__(self, other):
|
return _Nothing._singleton
|
||||||
return other.__class__ == _Nothing
|
|
||||||
|
|
||||||
def __ne__(self, other):
|
|
||||||
return not self == other
|
|
||||||
|
|
||||||
def __repr__(self):
|
def __repr__(self):
|
||||||
return "NOTHING"
|
return "NOTHING"
|
||||||
|
|
||||||
def __hash__(self):
|
|
||||||
return 0xc0ffee
|
|
||||||
|
|
||||||
|
|
||||||
NOTHING = _Nothing()
|
NOTHING = _Nothing()
|
||||||
"""
|
"""
|
||||||
|
|
Loading…
Reference in New Issue