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.

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

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

contextif-0.0.3-py3-none-any.whl (3.9 kB view details)

Uploaded Python 3

File details

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

File metadata

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

File hashes

Hashes for contextif-0.0.3.tar.gz
Algorithm Hash digest
SHA256 71cd825ee3b025c99ebadaee33c6707a2519bbaf36eb46bc5900942639ce3025
MD5 889714c04dfbc2c253bf36d77a8b3eff
BLAKE2b-256 e76ba08c8c594094887938df51ed44121a79636ecad83191880bec9ef0bb8a20

See more details on using hashes here.

File details

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

File metadata

  • Download URL: contextif-0.0.3-py3-none-any.whl
  • Upload date:
  • Size: 3.9 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.2 CPython/3.11.6

File hashes

Hashes for contextif-0.0.3-py3-none-any.whl
Algorithm Hash digest
SHA256 eacc1baa7637737f57edf525171866e9b0218065cf55fb961771cc256e6c8721
MD5 319b9e40a41ce3649ae3dfe39573c917
BLAKE2b-256 a3a596b1bacf52c67f7f04f2a50866d37eea45d603b83979b3ef4ee11797a164

See more details on using hashes here.

Supported by

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