FunnyDeco
Collection of useful decorators for python projects
Implements:
- Benchmarking util for methods
- Singleton pattern realisation for classes
- "Static" variables support in functions
Installation:
pip install funnydeco
Examples:
1. Benchmark decorator
from funnydeco.core import benchmark
# noinspection PyUnusedLocal
@benchmark
def long_loop() -> int:
"""
Demo func for example of benchmark
"""
result = 0
for i in range(int(1e7)):
result += i
print('foo')
return result
if __name__ == '__main__':
long_loop(print_benchmark=True, benchmark_name='Long loop procedure')
long_loop()
2. Singleton decorator
from funnydeco import singleton, SingletonReseter
from time import sleep
@singleton
class SlowInitClass(SingletonReseter):
"""
Demo class for example of singleton decorator
"""
def __init__(self):
self.variable = 1
print("I'm sleeping...")
sleep(3)
print("I'v woken up!")
if __name__ == '__main__':
print('First dumbass init:')
dumbass1 = SlowInitClass()
print(f'variable={dumbass1.variable}')
dumbass1.variable = 2
print()
print('Second dumbass init:')
dumbass2 = SlowInitClass()
print(f'variable={dumbass2.variable}')
print()
print('Third dumbass init:')
print('Temporary stopping singleton behaviour')
SlowInitClass().reset_singleton()
dumbass3 = SlowInitClass()
print(f'variable={dumbass3.variable}')
dumbass3.variable = 3
print()
print('Fourth dumbass init:')
dumbass4 = SlowInitClass()
print(f'variable={dumbass4.variable}')
print()
If you do not need to use reset_singleton functionality you may not to inherit your class from SingletonReseter
3. Static variables decorator
from funnydeco import static_vars
@static_vars(baz=False)
def foo(bar) -> None:
"""
Demo func for example of static_vars
"""
print(bar, foo.baz)
foo.baz = not foo.baz
if __name__ == '__main__':
foo(1)
foo(2)
foo(3)
foo(4)
Metadata
Release files for funnydeco 0.1.7
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | Actions |
|---|---|---|---|---|
| funnydeco-0.1.7.tar.gz | 15.0 kB | Without provenance | Details for funnydeco-0.1.7.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| funnydeco-0.1.7-py3-none-any.whl | Python 3 | none | any | Details for funnydeco-0.1.7-py3-none-any.whl |
Total release size: 30.3 kB
Release files / funnydeco-0.1.7.tar.gz
| Download URL | funnydeco-0.1.7.tar.gz |
|---|---|
| Size | 15.0 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
2b52215b7fb000a3602a58cd9e088f5af98fb611084c3179712507161e9565db
|
|
BLAKE2b-256 checksum How to use checksums |
0fe0a27380d2b2ad8c30268cc8ad24aa33d652dff9de3c7f619421792c9d8eda
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/3.4.2 importlib_metadata/4.12.0 pkginfo/1.8.3 requests/2.28.1 requests-toolbelt/0.9.1 tqdm/4.64.0 CPython/3.9.12
|
Release files / funnydeco-0.1.7-py3-none-any.whl
| Download URL | funnydeco-0.1.7-py3-none-any.whl |
|---|---|
| Size | 15.3 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
a2ce8221e5c760c9d5a6f23784a2944a8ab5e8edacdc2ddf0cfcbf800cc75f9b
|
|
BLAKE2b-256 checksum How to use checksums |
d474eb341c985fc9218168fa280047003a253b1b3c4a48a6dc6f161e6bb607e0
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/3.4.2 importlib_metadata/4.12.0 pkginfo/1.8.3 requests/2.28.1 requests-toolbelt/0.9.1 tqdm/4.64.0 CPython/3.9.12
|
Security for funnydeco 0.1.7
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
No provenance found
None of the files in this release were uploaded with provenance metadata.
A note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.
To learn more about protecting yourself from malicious actors, visit our package security documentation.