context module#
Contexts#
This module provides context management classes for maintaining state during design processing and instantiation. Contexts can be set to provide a value for a particular subtree of the design. If a context object is created in the class body, it will be set first, before any of the other fields are initialized, which means that subcircuits or components will see the new context value.
If a context is needed as part of the function, it does not need to be assigned
to a member field, and indeed doing so does not set the context value, instead
it is activated using a with block.
- class Context[source]#
Base class for context objects that maintain state during processing.
Context objects can be used as context managers to automatically push and pop context state, ensuring proper cleanup.
- classmethod require()[source]#
Get the current active context of this type, raising an error if not set.
- Returns:
The current context instance.
- Raises:
ValueError – If no context of this type is currently active.
- class ContextProperty(context, field=<function ContextProperty.<lambda>>)[source]#
Bases:
GenericProperty descriptor for accessing context objects.
Creates a property that automatically retrieves the current context and optionally applies a field accessor function.
>>> class DesignContext: ... def __init__(self): ... self.substrate = ContextProperty(SubstrateContext) >>> design = DesignContext() >>> # Accessing design.substrate will get the current substrate context