Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
S
satella
Manage
Activity
Members
Labels
Plan
Issues
1
Issue boards
Milestones
Wiki
Code
Merge requests
0
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Package Registry
Container Registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Terms and privacy
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
public
satella
Commits
77891d71
Commit
77891d71
authored
7 years ago
by
Piotr Maślanka
Browse files
Options
Downloads
Patches
Plain Diff
singleton comeback
parent
202cadd8
No related branches found
No related tags found
No related merge requests found
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
satella/coding/__init__.py
+1
-1
1 addition, 1 deletion
satella/coding/__init__.py
satella/coding/singleton.py
+28
-0
28 additions, 0 deletions
satella/coding/singleton.py
setup.py
+0
-1
0 additions, 1 deletion
setup.py
with
29 additions
and
2 deletions
satella/coding/__init__.py
+
1
−
1
View file @
77891d71
...
...
@@ -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__
=
[
...
...
This diff is collapsed.
Click to expand it.
satella/coding/singleton.py
0 → 100644
+
28
−
0
View file @
77891d71
"""
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
)
This diff is collapsed.
Click to expand it.
setup.py
+
0
−
1
View file @
77891d71
...
...
@@ -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
"
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment