treevalue.utils.singleton

SingletonMeta

class treevalue.utils.singleton.SingletonMeta[source]
Overview:

Meta class for singleton mode.

Example:
>>> class MyService(metaclass=SingletonMeta):
>>>     def get_value(self):
>>>         return 233
>>>
>>> s = MyService()
>>> s.get_value()    # 233
>>> s1 = MyService()
>>> s1 is s          # True
__call__()[source]

Call self as a function.

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
__call__(value)[source]

Call self as a function.

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
__eq__(other)[source]

Return self==value.

__hash__()[source]

Return hash(self).

__init__(mark)[source]

Initialize self. See help(type(self)) for accurate signature.

__repr__()[source]

Return repr(self).

property mark
Overview:

Get mark string of this mark object.

Returns:
  • mark (str): Mark string