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.3.1.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.3.1-py3-none-any.whl (3.2 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: contextclass-0.3.1.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.3.1.tar.gz
Algorithm Hash digest
SHA256 2b439b768663de05697e1aea8e23dc2bfbadcc28617169b80efc8dfc3f1b24b8
MD5 b0e605c1837bea0a2c323821623bc7ac
BLAKE2b-256 daf2870b64797db9b030c54f8963c7acb2a5b99fa04b8f7c318e56df19017fbc

See more details on using hashes here.

Provenance

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

File metadata

  • Download URL: contextclass-0.3.1-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.3.1-py3-none-any.whl
Algorithm Hash digest
SHA256 f620f0462edfafc0a26a71d824966b156179f563857337d53c18c7e655b6a8f3
MD5 eb5a7a2a46acb2153a5f4ec97716aafb
BLAKE2b-256 024416fbb6d95502e2779edce7ca9dfac93da72a77e853f4e3b3b10fc62735f3

See more details on using hashes here.

Provenance

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