treevalue.utils.singleton¶
SingletonMeta¶
ValueBasedSingletonMeta¶
-
class
treevalue.utils.singleton.
ValueBasedSingletonMeta
[source]¶ - Overview:
Meta class for value based singleton mode.
- Example:
>>> class MyData(metaclass=ValueBasedSingletonMeta): >>> def __init__(self, value): >>> self.__value = value >>> >>> @property >>> def value(self): >>> return self.__value >>> >>> d1 = MyData(1) >>> d1.value # 1 >>> d2 = MyData(1) >>> d3 = MyData(2) >>> d2 is d1 # True >>> d2 is d3 # False
SingletonMark¶
-
class
treevalue.utils.singleton.
SingletonMark
(value)[source]¶ - Overview:
Singleton mark for some situation. Can be used when some default value is needed, especially when None has meaning which is not default.
- Example:
>>> NO_VALUE = SingletonMark("no_value") >>> NO_VALUE is SingletonMark("no_value") # True
-
property
mark
¶ - Overview:
Get mark string of this mark object.
- Returns:
mark (
str
): Mark string