Skip to main content

Run the function only in a specific context

Project description

logo

Downloads Downloads codecov Hits-of-Code 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.

For convenience, after the first import of state, this variable becomes builtin and you can access it in other modules of your program without importing.

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.5.tar.gz (3.9 kB view details)

Uploaded Source

Built Distribution

contextif-0.0.5-py3-none-any.whl (4.2 kB view details)

Uploaded Python 3

File details

Details for the file contextif-0.0.5.tar.gz.

File metadata

  • Download URL: contextif-0.0.5.tar.gz
  • Upload date:
  • Size: 3.9 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/4.0.2 CPython/3.11.7

File hashes

Hashes for contextif-0.0.5.tar.gz
Algorithm Hash digest
SHA256 927b7dc0b39945137dba63581416ca3c3ccb28ab2d49d61e30d386ae7d7732b7
MD5 35f0cdd9330c32ebb805c6e3b1ac64f1
BLAKE2b-256 86a09c607b4b15f77f224e3b43dd38014cd43c8c21db701dd990f318db32ffda

See more details on using hashes here.

File details

Details for the file contextif-0.0.5-py3-none-any.whl.

File metadata

  • Download URL: contextif-0.0.5-py3-none-any.whl
  • Upload date:
  • Size: 4.2 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/4.0.2 CPython/3.11.7

File hashes

Hashes for contextif-0.0.5-py3-none-any.whl
Algorithm Hash digest
SHA256 402ddae000fc743eafd9fbba2b4b2e70df2d18883a238731981532a6c4a9ea15
MD5 07bb48bf6154d30e0833a05c1a3dc9a9
BLAKE2b-256 c85663bc357e214e429aa44716da395575e84ba23f363a042e6234401015d659

See more details on using hashes here.

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