Skip to main content

Run the function only in a specific context

Project description

Downloads Downloads codecov Test-Package Python versions PyPI version Checked with mypy Ruff

contextif: run the function only in a specific context

Sometimes we may need to run a function only if it happens in a strictly defined context. In this case, we can use this mini library.

Install it:

pip install contextif

And use:

from contextif import state

with state:
    state(print, 'hello,', 'world!')  # It will be printed.

state(print, "it's me, Mario!")  # It won't.

Using state as a function, you can pass another function and arguments to it there. It will be called only if it happens in a context created also using state. The function will not be called out of context.

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

contextif-0.0.1.tar.gz (3.0 kB view hashes)

Uploaded Source

Built Distribution

contextif-0.0.1-py3-none-any.whl (2.8 kB view hashes)

Uploaded Python 3

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page