asyncutils.context#
Contextual configuration system, inspired by the decimal module.
Attributes#
A |
Classes#
Context manager that temporarily sets the context of the current thread to a modified version of the provided context. Non-reentrant, but reusable with the exact same |
|
Version of |
Functions#
|
Return the current context for the active thread. |
|
Set the current context to for the active thread to |
Module Contents#
- class asyncutils.context.Context[source]#
- An object storing configuration for various functions and patterns in this library, for immutability and performance; that is, not loading
dataclassesfor@dataclass, which loadsinspect, triggering a cascade of imports.collections.namedtuple()is also unsuitable for this use case, since it behaves like a sequence.The order of the fields are kept in alphabetical order of submodule and in each submodule, and new fields may be added in the future.For consistency, each field is named in all caps with words separated by underscores, and prefixed by the name of the utility it is used in, followed by a concise description of what it configures.Tip
If you need to use any of the settings, you can find the documentation under the API reference for the utilities that use that setting.
Note
Refer to config for the factory default values of each setting.
Note
It is possible, but discouraged, to access these fields with attribute names that are not all uppercase.
Note
This is only type annotated as a dataclass for convenience and to avoid even more code duplication than there is now.
- ascurctx() nonreusablelocalcontext[source]#
Return a non-reusable context manager that sets the context to this context on entry.
ctx.ascurctx()is syntactic sugar fornonreusablelocalcontext(ctx)
- classmethod from_dct(dct: dict[str, Any], /) Self[source]#
Build an instance from the keys of the dictionary.
- pprint(file: asyncutils._internal.types.CanWriteAndFlush[str] = ..., *, pp: pprint.PrettyPrinter = ..., incl_newline: bool = ...) None[source]#
Pretty print the context to the provided file-like object
filewith thepprint.PrettyPrinterinstancepp, without a trailing newline ifincl_newline=Falseis specified.
- replace(/, **k: Any) Self[source]#
Return a new instance with the same values as this one besides the keyword arguments.
- replace_from_dct(dct: dict[str, Any], /) Self[source]#
Return a new instance with the same values as this one besides the keys of
dct.
- update(dct: dict[str, Any] = ..., /, **k: Any) None[source]#
Update the values of the instance with
dctif passed, then the keyword arguments.
- LEAKY_BUCKET_ADJMAP: _collections_abc.Sequence[tuple[float, tuple[float, float, float, float]]] = Ellipsis#
- MEMORY_MAPPED_IO_MANAGER_DEFAULT_CHECKSUM_ALG: asyncutils._internal.types.HashAlgorithm = Ellipsis#
- class asyncutils.context.localcontext(ctx: Context = ..., **k: Any)[source]#
Context manager that temporarily sets the context of the current thread to a modified version of the provided context. Non-reentrant, but reusable with the exact same
new_ctx.Note that the context of the current thread is to be set to a shallow copy of
ctx, defaulting to the current context, with replacements from the keyword arguments.- async __aexit__(exc_typ: asyncutils._internal.types.ExcType, exc_val: BaseException, exc_tb: types.TracebackType, /) None[source]#
- async __aexit__(exc_typ: None, exc_val: None, exc_tb: None, /) None
Reset the context to the previous.
- __exit__(exc_typ: asyncutils._internal.types.ExcType, exc_val: BaseException, exc_tb: types.TracebackType, /) None[source]#
- __exit__(exc_typ: None, exc_val: None, exc_tb: None, /) None
Reset the context to the previous.
- class asyncutils.context.nonreusablelocalcontext(ctx: Context = ..., **k: Any)[source]#
Bases:
localcontextVersion of
localcontextthat is not reusable. Use this to avoid subtle bugs, especially since it’s not that expensive to instantiate aContext.Note that the context of the current thread is to be set to a shallow copy of
ctx, defaulting to the current context, with replacements from the keyword arguments.
- asyncutils.context.setcontext(ctx: Context, /) None[source]#
Set the current context to for the active thread to
ctx.
- asyncutils.context.all_contextual_consts: frozenset[str]#
A
frozensetof all contextual constant names, for use in validating that only valid contextual constants are accessed or modified.Note
These names are not listed by calling
dir()on this submodule, since there are so many of them (86 as of now!) and more may be added in the future, and the recommended way to get their values is to query them on the actual context object anyway. They are still provided below to facilitate type checking.