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 image 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.3.0.tar.gz (43.1 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.3.0-py3-none-any.whl (3.3 kB view details)

Uploaded Python 3

File details

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

File metadata

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

File hashes

Hashes for contextclass-0.3.0.tar.gz
Algorithm Hash digest
SHA256 45c0797fd20eef944546aa321772749c0d4d5c3c24326d7bf7374caeccdbf1e1
MD5 73ca47aa64a823c5eb9c326a9c107aad
BLAKE2b-256 9d20f8df0da457fe6736edc8a534e32a4d882aff58b9b10c767a7ba9e3c07f72

See more details on using hashes here.

Provenance

The following attestation bundles were made for contextclass-0.3.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.3.0-py3-none-any.whl.

File metadata

  • Download URL: contextclass-0.3.0-py3-none-any.whl
  • Upload date:
  • Size: 3.3 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.3.0-py3-none-any.whl
Algorithm Hash digest
SHA256 e16171ab75f5219a160553ac3467d3563278c52febbc875067a9b611eec0fbc6
MD5 b2a453888cb4119a9c5b387f0a141b68
BLAKE2b-256 42e6480f5406fccda2723ec19cf368de094fcfadc442adb6f4aef2c99f033ad5

See more details on using hashes here.

Provenance

The following attestation bundles were made for contextclass-0.3.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