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())
Release files for single-ins 0.0.1
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | |
|---|---|---|---|
| single-ins-0.0.1.tar.gz | 2.5 kB | Details |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Reset |
|---|---|---|---|---|
| single_ins-0.0.1-py3-none-any.whl | Python 3 | none | any | Details |
Total release size: 6.3 kB
Release files / single-ins-0.0.1.tar.gz
| Download URL | single-ins-0.0.1.tar.gz |
|---|---|
| Size | 2.5 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
827365267f220a6003c7980fa14efec38e7cf8cf9fa095b05b2de90f833b83b0
|
|
BLAKE2b-256 checksum How to use checksums |
911159da03cf273a09a515c73592643a0c663b79a0ac0810e85ac87a5abd1de8
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/5.1.0 CPython/3.11.7
|
Release files / single_ins-0.0.1-py3-none-any.whl
| Download URL | single_ins-0.0.1-py3-none-any.whl |
|---|---|
| Size | 3.8 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
850854e4023c9af916e9c049ee3d71cccb619058ec52d0f1c6ab82befd28111c
|
|
BLAKE2b-256 checksum How to use checksums |
f67a066752b5dd2b24107795de369b6073c9fb4ae7f013e143585d0491b2d263
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/5.1.0 CPython/3.11.7
|