A nice interface to context variables
Project description
contextmodel
Alternative interface to context variables for practical scenarios.
>>> from contextmodel import context_get, context_set
>>> from dataclasses import dataclass
>>> @dataclass
... class Foo:
... x: int | None = None
>>> @context_set(Foo(x=1))
... def f() -> None:
... print(context_get(Foo))
>>> f()
Foo(x=1)
>>> from contextmodel import ContextAPIGetter, ModelGetter
>>> from typing import ClassVar
>>> @dataclass
... class Foo:
... context = ContextAPIGetter()
... current = ModelGetter()
... x: int | None = None
>>> with Foo.context.init(x=2):
... print(Foo.context.get())
Foo(x=2)
>>> @Foo.context.init(x=3)
... def f() -> None:
... print(context_get(Foo))
>>> f()
Foo(x=3)
>>> def oops() -> None:
... print(Foo.current)
>>> oops()
Traceback (most recent call last):
...
LookupError: expected a context_set(Foo(...)) prior to this call
Works with type hints:
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
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file contextmodel-0.3.1.tar.gz.
File metadata
- Download URL: contextmodel-0.3.1.tar.gz
- Upload date:
- Size: 43.6 kB
- Tags: Source
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
1c9fd20c29bf476523faa466a53f4f21f13f82c25e1b4d8d60e95aab5ed7576e
|
|
| MD5 |
5812e1494f76fedd0a1c983d7b9b82da
|
|
| BLAKE2b-256 |
f8ead0b22f4ca8b6cd4aa858c89fa065e61bcdf98bd62bb853317de459b7b5af
|
Provenance
The following attestation bundles were made for contextmodel-0.3.1.tar.gz:
Publisher:
ci.yml on johnslavik/contextmodel
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
contextmodel-0.3.1.tar.gz -
Subject digest:
1c9fd20c29bf476523faa466a53f4f21f13f82c25e1b4d8d60e95aab5ed7576e - Sigstore transparency entry: 929627089
- Sigstore integration time:
-
Permalink:
johnslavik/contextmodel@725952a023d1e3d14450942cb3da57bfacbb12da -
Branch / Tag:
refs/tags/v0.3.1 - Owner: https://github.com/johnslavik
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
ci.yml@725952a023d1e3d14450942cb3da57bfacbb12da -
Trigger Event:
push
-
Statement type:
File details
Details for the file contextmodel-0.3.1-py3-none-any.whl.
File metadata
- Download URL: contextmodel-0.3.1-py3-none-any.whl
- Upload date:
- Size: 3.8 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
a133bb96c251df84baf99897f4fc67d2f4e1522be1093d0636b74996d51e088c
|
|
| MD5 |
0b31534d95b6a1c55b063dbe0939acc9
|
|
| BLAKE2b-256 |
222cd4343798e655ec21c09c5a372a8311da7d3f5db55a60265d066ca87fb660
|
Provenance
The following attestation bundles were made for contextmodel-0.3.1-py3-none-any.whl:
Publisher:
ci.yml on johnslavik/contextmodel
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
contextmodel-0.3.1-py3-none-any.whl -
Subject digest:
a133bb96c251df84baf99897f4fc67d2f4e1522be1093d0636b74996d51e088c - Sigstore transparency entry: 929627090
- Sigstore integration time:
-
Permalink:
johnslavik/contextmodel@725952a023d1e3d14450942cb3da57bfacbb12da -
Branch / Tag:
refs/tags/v0.3.1 - Owner: https://github.com/johnslavik
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
ci.yml@725952a023d1e3d14450942cb3da57bfacbb12da -
Trigger Event:
push
-
Statement type: