cobra.util.context
¶
Context manager for the package.
Module Contents¶
Classes¶
Define a base context manager. |
Functions¶
|
Search for a context manager. |
|
Simplify the context management of simple object attributes. |
- class cobra.util.context.HistoryManager(**kwargs)[source]¶
Define a base context manager.
It records a list of actions to be taken at a later time. This is used to implement context managers that allow temporary changes to a cobra.core.Model.
- cobra.util.context.get_context(obj: cobra.Object) Optional[HistoryManager] [source]¶
Search for a context manager.
- Parameters
obj (cobra.Object) – The cobra.Object for which to search context manager.
- Returns
HistoryManager instance, or None if no context manager is found.
- Return type
HistoryManager or None
- Raises
AttributeError – If no context manager is found.
IndexError – If no context manager is found.
- cobra.util.context.resettable(func: Callable[[Any], Any]) Callable[[Any], Any] [source]¶
Simplify the context management of simple object attributes.
It gets the value of the attribute prior to setting it, and stores a function to set the value to the old value in the cobra.util.HistoryManager.
- Parameters
func (callable) – The function to decorate.
- Returns
The decorated function.
- Return type
callable