reslot
A class decorator that lets you use @cached_property on classes with __slots__.
The decorated class needs a __dict__ slot, but there won't exactly be a
dictionary in it. Instead, @reslot will give it a custom MutableMapping
with its own slots. @cached_property will keep its cache there.
The custom MutableMapping's slots will be exactly the slots needed to store
the results of every @cached_property that was on the class at the time it
was declared. This minimizes the memory footprint and makes lookup speedy.
Usage
from functools import cached_property
from reslot import reslot
BEANED = False
@reslot
class Spam:
__slots__ = ("__dict__",)
@cached_property
def eggs(self):
return {"delicious": False}
@cached_property
def beans(self):
global BEANED
BEANED = True
return {"spam": 111000, "delicious": True}
spam = Spam()
print(spam.eggs) # {"delicious": False}
print(BEANED) # False
print(spam.beans) # {"spam": 111000, "delicious": True}
print(BEANED) # True
Metadata
Release files for reslot 0.10
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | |
|---|---|---|---|
| reslot-0.10.tar.gz | 3.7 kB | Details |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Reset |
|---|---|---|---|---|
| reslot-0.10-py3-none-any.whl | Python 3 | none | any | Details |
Total release size: 7.5 kB
Release files / reslot-0.10.tar.gz
| Download URL | reslot-0.10.tar.gz |
|---|---|
| Size | 3.7 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
27d3dda00327cdaf72a1d045d39e46eec6324be0c9a219e73c8e69df9102037d
|
|
BLAKE2b-256 checksum How to use checksums |
be8a130f01a603f95ca7c39ecf0fb9515154de159a42cc6641e76bd469f9ec77
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/6.0.1 CPython/3.12.3
|
Release files / reslot-0.10-py3-none-any.whl
| Download URL | reslot-0.10-py3-none-any.whl |
|---|---|
| Size | 3.9 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
2749039d152f74cb52eba4b662aad334a05a4811a7ba9831d2f72c99e69c2012
|
|
BLAKE2b-256 checksum How to use checksums |
071c9fb09787fdd0a7d2ec5d1299014f638d2be1ef876bc5cf4cc3be29800630
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/6.0.1 CPython/3.12.3
|