Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/syntapy/singleton
Simple python singleton metaclass
https://github.com/syntapy/singleton
Last synced: 22 days ago
JSON representation
Simple python singleton metaclass
- Host: GitHub
- URL: https://github.com/syntapy/singleton
- Owner: syntapy
- License: bsd-3-clause
- Created: 2021-08-12T15:01:35.000Z (over 3 years ago)
- Default Branch: main
- Last Pushed: 2021-09-24T05:12:50.000Z (over 3 years ago)
- Last Synced: 2023-07-02T02:10:58.827Z (over 1 year ago)
- Language: Python
- Size: 10.7 KB
- Stars: 0
- Watchers: 2
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
Makes any python class a singleton by calling
```python
from singleton import Singletonclass MyClass(metaclass=Singleton, Baseclasses...):
pass
```This is method 2 taken from [here](https://stackoverflow.com/questions/6760685/creating-a-singleton-in-python) but adapted to support separate instances for different constructor arguments
ToDo
----
Approaches to offer
- metaclass
- class decorator
- base classRequirements are
- [ ] Singleton for each class for each combo of arguments
- i.e. can have multiple instances of same class if they have different constructor arguments
- [x] metaclass
- [ ] class decorator
- [ ] base class
- [ ] A separate object contains all instances of each class
- Do not e.g. have a single dict containing every instances of the singleton (that is just bloated, and any bugs could leak out to other different classes
- [ ] metaclass (probably not possible)
- [ ] class decorator
- [ ] base class