Skip to content
Snippets Groups Projects
Commit 77891d71 authored by Piotr Maślanka's avatar Piotr Maślanka
Browse files

singleton comeback

parent 202cadd8
No related branches found
No related tags found
No related merge requests found
......@@ -13,7 +13,7 @@ from .typecheck import typed, Callable, Sequence, \
Number, coerce, Set, Dict, List, Tuple, checked_coerce, for_argument, \
precondition, PreconditionError
from .structures import TimeBasedHeap, Heap, typednamedtuple, OmniHashableMixin
from singleton_decorator import singleton as Singleton
from .singleton import Singleton
__all__ = [
......
"""
Taken from module pypi/singleton-decorator
"""
class _SingletonWrapper:
"""
A singleton wrapper class. Its instances would be created
for each decorated class.
"""
def __init__(self, cls):
self.__wrapped__ = cls
self._instance = None
def __call__(self, *args, **kwargs):
"""Returns a single instance of decorated class"""
if self._instance is None:
self._instance = self.__wrapped__(*args, **kwargs)
return self._instance
def Singleton(cls):
"""
A singleton decorator. Returns a wrapper objects. A call on that object
returns a single instance object of decorated class. Use the __wrapped__
attribute to access decorated class directly in unit tests
"""
return _SingletonWrapper(cls)
......@@ -9,7 +9,6 @@ setup(keywords=['ha', 'high availability', 'scalable', 'scalability', 'server'],
"six",
"monotonic",
"typing",
'singleton-decorator==1.0.0'
],
tests_require=[
"nose", "mock", "coverage"
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment