-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Update README.md with singleton usage examples - Add new file examples/singleton_usage.py - Remove setup.cfg This commit enhances the documentation by adding detailed examples of singleton usage in the README.md and includes a new file with additional singleton examples. The removal of setup.cfg is part of a configuration cleanup.
- Loading branch information
1 parent
7217ffa
commit 1d7db27
Showing
3 changed files
with
53 additions
and
16 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
from zeeland import Singleton, singleton | ||
|
||
|
||
@singleton() | ||
class TestSingleton: | ||
pass | ||
|
||
|
||
instance1 = TestSingleton() | ||
instance2 = TestSingleton() | ||
|
||
assert instance1 is instance2 | ||
|
||
|
||
class TestSingletonWithArgs(metaclass=Singleton): | ||
def __init__(self, value): | ||
self.value = value | ||
|
||
|
||
instance1 = TestSingletonWithArgs("test1") | ||
instance2 = TestSingletonWithArgs("test2") | ||
|
||
assert instance1 is instance2 | ||
assert instance1.value == "test1" |