Skip to main content

Provides Go-like defer

Powered by Yamato Nagata

GitHub

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

Metadata

Release files for defern 1.0.0

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for defern 1.0.0
File Size Uploaded Provenance
defern-1.0.0.tar.gz 4.4 kB Without provenance Details

Built distribution (wheel)

Table of built distributions (wheels) for defern 1.0.0
File Interpreter ABI Platform
defern-1.0.0-py3-none-any.whl Python 3 none any Details

Total release size: 8.8 kB

Release files / defern-1.0.0.tar.gz

Download URL defern-1.0.0.tar.gz
Size 4.4 kB
Tags Source
SHA-256 checksum
How to use checksums
1dce60b7e8761446f3d1fd1c2c13dded7f33c80e26a38fdb0153ee9f53fb4bb5
BLAKE2b-256 checksum
How to use checksums
04e43a11d2b975077848c237817486d607484a3a4ac300b98070e4ba45c29d6e
Upload date
Uploaded using Trusted Publishing?
What is 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

Release files / defern-1.0.0-py3-none-any.whl

Download URL defern-1.0.0-py3-none-any.whl
Size 4.4 kB
Tags Python 3
SHA-256 checksum
How to use checksums
768c73a124b6476c40f7893f5fac05d1e2e49c67ab5ec8c5a2a300402988e7b8
BLAKE2b-256 checksum
How to use checksums
2b4f54c7d933b8f71d8060010a20cf32bb2d8dd52e2a4aa15801e6cef2a78b38
Upload date
Uploaded using Trusted Publishing?
What is 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

Security for defern 1.0.0

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.

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page