Skip to main content

A nice interface to context variables

This project has been archived.

The maintainers of this project have marked this project as archived. No new releases are expected.

Project description

contextclass

Alternative interface to context variables for practical scenarios.

>>> from contextclass import ContextLocal, enter, current
>>> from dataclasses import dataclass

>>> @dataclass
... class Foo(ContextLocal):
...     x: int | None = None

>>> @enter(Foo, x=1)
... def f() -> None:
...     print(current(Foo))
>>> f()
Foo(x=1)

>>> with Foo.context(x=2):
...     print(Foo.current.x)
2

>>> @Foo.context(x=3)
... def f() -> None:
...     print(Foo.current.x)
>>> f()
3

Works with type hints:

image

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

contextclass-0.4.0.tar.gz (43.0 kB view details)

Uploaded Source

Built Distribution

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

contextclass-0.4.0-py3-none-any.whl (3.2 kB view details)

Uploaded Python 3

File details

Details for the file contextclass-0.4.0.tar.gz.

File metadata

  • Download URL: contextclass-0.4.0.tar.gz
  • Upload date:
  • Size: 43.0 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.7

File hashes

Hashes for contextclass-0.4.0.tar.gz
Algorithm Hash digest
SHA256 5537b72b7e4c826862026f4e941858d7f5612f964eb2f5e820debbfb5cc9c515
MD5 7f186022ce541a09827f943fcf37150a
BLAKE2b-256 fa3862990c7cf0e82a6c0f8396fdae8661ee56f5bb8528338a1bc624a39a6c46

See more details on using hashes here.

Provenance

The following attestation bundles were made for contextclass-0.4.0.tar.gz:

Publisher: ci.yml on johnslavik/contextclass

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file contextclass-0.4.0-py3-none-any.whl.

File metadata

  • Download URL: contextclass-0.4.0-py3-none-any.whl
  • Upload date:
  • Size: 3.2 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.7

File hashes

Hashes for contextclass-0.4.0-py3-none-any.whl
Algorithm Hash digest
SHA256 176317e1fdece3457ffdd5d4eea4f0c4a534f03576c2480465c1b132974d7c64
MD5 89a3267d297b8cc27bf30a64a380c80e
BLAKE2b-256 d491b84fc8ef430f504bf1d9fd6b1ca3a64870334d790ab5043f48a5be5b295b

See more details on using hashes here.

Provenance

The following attestation bundles were made for contextclass-0.4.0-py3-none-any.whl:

Publisher: ci.yml on johnslavik/contextclass

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

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