This module provides Set, a context manager which sets one or more contextvars variables upon activation and resets them to their previous values at exit.
Usage:
import contextvars, with_contextvars
A = contextvars.ContextVar("A")
B = contextvars.ContextVar("B")
A.set("Hello,")
B.set("world!")
print(A.get(), B.get())
# prints: Hello, world!
with with_contextvars.Set((A, "other"), (B, "value")):
print(A.get(), B.get())
# prints: other value
print(A.get(), B.get())
# prints: Hello, world!
Even the entirety of variable assignments of a contextvars.Context object (as obtained from contextvars.copy_context()) can be activated by initializing Set with its items:
with with_contextvars.Set(*context.items()):
...
However, using contextvars.Context.run() is more efficient and should be preferred where possible.
More information can be found in the documentation of Set.
Release files for with-contextvars 0.1.2
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | |
|---|---|---|---|
| with_contextvars-0.1.2.tar.gz | 2.8 kB | Details |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Reset |
|---|---|---|---|---|
| with_contextvars-0.1.2-py3-none-any.whl | Python 3 | none | any | Details |
Total release size: 6.4 kB
Release files / with_contextvars-0.1.2.tar.gz
| Download URL | with_contextvars-0.1.2.tar.gz |
|---|---|
| Size | 2.8 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
bb26d9a51f310cef9fb306cb04b09e87a3c0378059327bd2b5a6ea66c5ab7ce7
|
|
BLAKE2b-256 checksum How to use checksums |
061d1225d1c36e074c31fa75267aa70042a086c0c21f35a20a42e8eef628ed32
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
poetry/1.7.0 CPython/3.9.2 Linux/5.10.0-26-amd64
|
Release files / with_contextvars-0.1.2-py3-none-any.whl
| Download URL | with_contextvars-0.1.2-py3-none-any.whl |
|---|---|
| Size | 3.7 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
8aae290cd363aa35560e4f1c3959a98b025457b8319c8d63f624b7825e51996e
|
|
BLAKE2b-256 checksum How to use checksums |
fdc80269fdca6fab81ec9aa487df5bc3f09fb4577fb3d49a6f6682a5cb466579
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
poetry/1.7.0 CPython/3.9.2 Linux/5.10.0-26-amd64
|