grscheller.fp.nothingness
Singleton class representing nothingness
1# Copyright 2023-2024 Geoffrey R. Scheller 2# 3# Licensed under the Apache License, Version 2.0 (the "License"); 4# you may not use this file except in compliance with the License. 5# You may obtain a copy of the License at 6# 7# http://www.apache.org/licenses/LICENSE-2.0 8# 9# Unless required by applicable law or agreed to in writing, software 10# distributed under the License is distributed on an "AS IS" BASIS, 11# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12# See the License for the specific language governing permissions and 13# limitations under the License. 14 15"""### Singleton class representing nothingness 16 17""" 18from __future__ import annotations 19 20__all__ = [ '_NoValue', 'noValue' ] 21 22from typing import Final 23 24class _NoValue(): 25 """#### Singleton class representing a missing value. 26 27 * similar to `None` but while 28 * `None` represent "returned no values" 29 * `noValue: _NoValue = _NoValue()` represents the absence of a value 30 31 """ 32 __slots__ = () 33 34 def __new__(cls) -> _NoValue: 35 if not hasattr(cls, 'instance'): 36 cls.instance = super(_NoValue, cls).__new__(cls) 37 return cls.instance 38 39 def __repr__(self) -> str: 40 return 'noValue' 41 42 def __eq__(self, other: object) -> bool: 43 if self is other: 44 return True 45 return False 46 47noValue: Final[_NoValue] = _NoValue()
class
_NoValue:
25class _NoValue(): 26 """#### Singleton class representing a missing value. 27 28 * similar to `None` but while 29 * `None` represent "returned no values" 30 * `noValue: _NoValue = _NoValue()` represents the absence of a value 31 32 """ 33 __slots__ = () 34 35 def __new__(cls) -> _NoValue: 36 if not hasattr(cls, 'instance'): 37 cls.instance = super(_NoValue, cls).__new__(cls) 38 return cls.instance 39 40 def __repr__(self) -> str: 41 return 'noValue' 42 43 def __eq__(self, other: object) -> bool: 44 if self is other: 45 return True 46 return False
Singleton class representing a missing value.
- similar to
None
but whileNone
represent "returned no values"noValue: _NoValue = _NoValue()
represents the absence of a value