Handy Decorators
This is a set of handy decorators which one can use for their day-to-day life coding.
Installation Method
Install it via pip
pip install handy-decorators
Description
The set of decorators contain some daily needed decorators for being used in our day to day coding life. This has following set of decorators.
trycatch
This decorator surounds your function with a try-except block and if your code/function raises an exception, it's caught by this decorator and reported by logging.
>>> from decorators import trycatch
>>> @trycatch
... def func():
... print(0/0) # Division by 0 must raise exception
...
>>> func()
Exception occurred: [integer division or modulo by zero]
>>>
timer
This decorator will calculate a time required in seconds by your function for execution.
>>> from decorators import timer
>>> @timer
... def a():
... import time
... print('Hi')
... time.sleep(1)
...
>>> a()
Hi
Time taken by the function is [1.00103902817] sec
>>>
singleton
This decorator is for making your class singleton.
The features given by this decorator are:
- If instances of same class are created with same args and kwargs, decorator will return previously existing instance
- If instances of same class are created with different args and kwargs, decorator will create a different one for you and store the newly created instance
>>> from decorators import singleton
>>>
>>> @singleton
... class A:
... def __init__(self, *args, **kwargs):
... pass
...
>>>
>>> a = A(name='Siddhesh')
>>> b = A(name='Siddhesh', lname='Sathe')
>>> c = A(name='Siddhesh', lname='Sathe')
>>> a is b # has to be different
False
>>> b is c # has to be same
True
>>>
Please create an issue if more decorators are needed.
Metadata
Release files for handy-decorators 0.0.7
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| handy_decorators-0.0.7-py2-none-any.whl | Python 2 | none | any | Details for handy_decorators-0.0.7-py2-none-any.whl |
Release files / handy_decorators-0.0.7-py2-none-any.whl
| Download URL | handy_decorators-0.0.7-py2-none-any.whl |
|---|---|
| Size | 15.4 kB |
| Tags | Python 2 |
|
SHA-256 checksum How to use checksums |
953deea0a2836d2944436b2b2e6d9e4d980d9b37fc1a75b0fc95cbc8a018aa27
|
|
BLAKE2b-256 checksum How to use checksums |
bcf899c760e4f1c6226add1b358a740fe1b1d5bb5fe488dd601acb1446a3bda2
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/1.13.0 pkginfo/1.5.0.1 requests/2.22.0 setuptools/40.8.0 requests-toolbelt/0.9.1 tqdm/4.31.1 CPython/2.7.12
|
Security for handy-decorators 0.0.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.