Provides Go-like `defer`
Project description
Provides Go-like defer
Powered by Yamato Nagata
installation:
$ pip install defern
from defern import defern, deferner, defern_this, here
def defer_multiple_function(frame):
defern(lambda: print("it's middle 7th"), frame=frame)
defern(lambda: print("it's middle 8th"), frame=frame)
print("Hi")
defern(lambda: print("it's middle 1st")) # you can pass function to run after return.
defern(lambda: print("it's middle 2nd"))
defern(print, "it's middle 3rd") # passed args and kwargs after function will given to function.
@deferner
def defer_this(number: str):
print("it's middle", number) # you can create function which runs after return with `@deferner`
defer_this("4th")
defer_this("5th", frame=here())
@defern_this # wrap function to create procedure which automatically runs after return
def defer_this_now():
print("it's middle 6th")
defer_multiple_function(here()) # here() to get currentFrame and pass it to `defern` or function created with `deferner`
# with name `frame` will create `defern` to that frame
print('ended')
# Hi
# ended
# it's middle 1st
# it's middle 2nd
# it's middle 3rd
# it's middle 4th
# it's middle 5th
# it's middle 6th
# it's middle 7th
# it's middle 8th
Project details
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
defern-1.0.0.tar.gz
(4.4 kB
view details)
Built Distribution
File details
Details for the file defern-1.0.0.tar.gz
.
File metadata
- Download URL: defern-1.0.0.tar.gz
- Upload date:
- Size: 4.4 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/3.2.0 pkginfo/1.6.1 requests/2.24.0 setuptools/49.2.1 requests-toolbelt/0.9.1 tqdm/4.51.0 CPython/3.9.0
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 1dce60b7e8761446f3d1fd1c2c13dded7f33c80e26a38fdb0153ee9f53fb4bb5 |
|
MD5 | bc705eddc96e51ae7c54420abc772a33 |
|
BLAKE2b-256 | 04e43a11d2b975077848c237817486d607484a3a4ac300b98070e4ba45c29d6e |
File details
Details for the file defern-1.0.0-py3-none-any.whl
.
File metadata
- Download URL: defern-1.0.0-py3-none-any.whl
- Upload date:
- Size: 4.4 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/3.2.0 pkginfo/1.6.1 requests/2.24.0 setuptools/49.2.1 requests-toolbelt/0.9.1 tqdm/4.51.0 CPython/3.9.0
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 768c73a124b6476c40f7893f5fac05d1e2e49c67ab5ec8c5a2a300402988e7b8 |
|
MD5 | d388b919d4dec9d2fc6b8508e58b8c12 |
|
BLAKE2b-256 | 2b4f54c7d933b8f71d8060010a20cf32bb2d8dd52e2a4aa15801e6cef2a78b38 |