A few useful decorators for Python functions, classes, class methods, and properties.
Project description
jafdecs: Just A Few Decorators
Pretty useful decorators for Python functions, classes, and class methods.
Write Once, Read Many on Class Properties
If a class property takes a long time to compute and is referenced many times, it is useful to lazily compute it once (when it is first referenced) and cache the result for later references. This is where the worm submodule comes in.
class SlowExample:
@property
def hard_property(self):
import time
time.sleep(5)
print('This took a long time to compute!')
return 5
ex = SlowExample()
print(ex.hard_property)
print(ex.hard_property)
In the example above, the code will take around 10 seconds to run. But it only needs to take 5 seconds if the property’s value is cached, like in the example below.
from jafdecs import worm
@worm.onproperties
class QuickerExample:
@property
def hard_property(self):
import time
time.sleep(5)
print('This took a long time to compute!')
return 5
ex = QuickerExample()
print(ex.hard_property)
print(ex.hard_property)
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
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file jafdecs-0.1.0a0.tar.gz.
File metadata
- Download URL: jafdecs-0.1.0a0.tar.gz
- Upload date:
- Size: 2.7 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/4.0.2 CPython/3.10.6
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
4eeb8546a611569aa7c194e404ca9757ed714fbd4f1acbc898ca086d55e88303
|
|
| MD5 |
7379f9b7d4ec4c27bf04aec6364dd141
|
|
| BLAKE2b-256 |
e6adee4856afd4e8419397be2636cfbf09cfd6b0718d0436083a8154629ceb59
|
File details
Details for the file jafdecs-0.1.0a0-py3-none-any.whl.
File metadata
- Download URL: jafdecs-0.1.0a0-py3-none-any.whl
- Upload date:
- Size: 2.9 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/4.0.2 CPython/3.10.6
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
3360ca77f22475c3e0f911dc798e19fcc3cc0fb41c84665dc2f79c32e76ee4e9
|
|
| MD5 |
c9ec81d14bbba3f1f0f8d92ac97c5f8a
|
|
| BLAKE2b-256 |
0ea1a739c8345b85fdf6d4fe9a96d830c6117dcead94ec4e3a9283cbe09f66e3
|