Single Instance
Project description
An Easy-Used Single Instance package
- support simple single instance
- support
install
pip install single-ins
how to use
SingleHashableInstance
from single_ins.hashable_si import SingleHashableInstance
from dataclasses import dataclass
class Foo(SingleHashableInstance):
def __init__(self, v):
self.v = v
def __hash__(self):
return self.v
@dataclass
class Data(SingleHashableInstance):
v: int
def __hash__(self):
return self.v
if __name__ == '__main__':
assert id(Foo(1)) == id(Foo(1))
assert id(Foo(2)) != id(Foo(1))
assert id(Data(1)) == id(Data(1))
assert id(Data(2)) != id(Data(1))
SingleEqualableInstance
from single_ins import SingleEqualableInstance
class Foo(SingleEqualableInstance):
def __init__(self, v, b=1, *args, **kwargs):
self.v = v
def __eq__(self, other):
if not isinstance(other, Foo):
return False
return self.v == other.v
if __name__ == '__main__':
assert id(Foo(1)) == id(Foo(1))
assert id(Foo(2)) != id(Foo(1))
SingleInstance
from single_ins import SingleInstance
class Foo(SingleInstance):
def __init__(self):
pass
if __name__ == '__main__':
assert id(Foo()) == id(Foo())
assert id(Foo.instance) == id(Foo())
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
single-ins-0.0.1.tar.gz
(2.5 kB
view details)
Built Distribution
File details
Details for the file single-ins-0.0.1.tar.gz
.
File metadata
- Download URL: single-ins-0.0.1.tar.gz
- Upload date:
- Size: 2.5 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/5.1.0 CPython/3.11.7
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 827365267f220a6003c7980fa14efec38e7cf8cf9fa095b05b2de90f833b83b0 |
|
MD5 | adb65eb3bdac352dd06b116c691a3932 |
|
BLAKE2b-256 | 911159da03cf273a09a515c73592643a0c663b79a0ac0810e85ac87a5abd1de8 |
File details
Details for the file single_ins-0.0.1-py3-none-any.whl
.
File metadata
- Download URL: single_ins-0.0.1-py3-none-any.whl
- Upload date:
- Size: 3.8 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/5.1.0 CPython/3.11.7
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 850854e4023c9af916e9c049ee3d71cccb619058ec52d0f1c6ab82befd28111c |
|
MD5 | 91538cf4418f17c2ea2d9492e6b6d8ac |
|
BLAKE2b-256 | f67a066752b5dd2b24107795de369b6073c9fb4ae7f013e143585d0491b2d263 |