pydefer
pydefer aims to emulate the same experience you get from using Golang's defer keyword. pydefer allows you to execute a function around a given wrapped function after the wrapped function has executed.
Installing
$ pip install pydefer
or
$ pipenv install pydefer
Usage
Here's a basic example of using defer to print the sequence of numbers between [6,10] after print_sequence is called (which calls the sequence of numbers between [1,5]).
>>> from pydefer.defer import defer
>>>
>>> @defer(print,6,7,8,9,10)
... def print_sequence():
... print(1,2,3,4,5)
...
>>> print_seqeuence()
1 2 3 4 5
6 7 8 9 10
Some more complex use cases of pydefer is to be able to close files and not have to worry about closing them yourself in the actual function. Another use case is possibly session management for a web app after a user visits different routes.
Here's the aforementioned more complex example of deferring of closing a file.
from python.defer import defer
@defer(open('employee_data.txt','r').close)
def update_employee(e_id):
f = open('employee_data.txt','w')
# DO STUFF TO FILE
f.write(e_id.salary)
# DO MORE STUFF LATER ON
In the above example, you do not need to manage the file anywhere inside the function as the defer function wrapper will close that file for you after the update_employee function has finished.
Metadata
Release files for pydefer 0.0.2
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 |
|---|---|---|---|---|
| pydefer-0.0.2.tar.gz | 2.4 kB | Without provenance | Details for pydefer-0.0.2.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| pydefer-0.0.2-py3-none-any.whl | Python 3 | none | any | Details for pydefer-0.0.2-py3-none-any.whl |
Total release size: 5.9 kB
Release files / pydefer-0.0.2.tar.gz
| Download URL | pydefer-0.0.2.tar.gz |
|---|---|
| Size | 2.4 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
7fd71e5567c643542d0e92f43a9500ad99f44979d82786436f7f58e150b557ad
|
|
BLAKE2b-256 checksum How to use checksums |
089d8a3eb93ed90e1ebc9886aa708af95d2b4b63a1c61b0c7d23ee078710ceba
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/3.1.1 pkginfo/1.5.0.1 requests/2.23.0 setuptools/46.1.3 requests-toolbelt/0.9.1 tqdm/4.45.0 CPython/3.7.5
|
Release files / pydefer-0.0.2-py3-none-any.whl
| Download URL | pydefer-0.0.2-py3-none-any.whl |
|---|---|
| Size | 3.6 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
2b4e8c810be4cc80aa2a4f494142d746afd67c5f6fbb2c8d929370b9c709c6be
|
|
BLAKE2b-256 checksum How to use checksums |
608e931ca84f3503605860da3e5daaa7db261bc8cacf4e9534385dc452d5357e
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/3.1.1 pkginfo/1.5.0.1 requests/2.23.0 setuptools/46.1.3 requests-toolbelt/0.9.1 tqdm/4.45.0 CPython/3.7.5
|
Security for pydefer 0.0.2
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.