17.1.1.8.1.2. cobra.util.context
¶
Context manager for the package.
17.1.1.8.1.2.1. Module Contents¶
17.1.1.8.1.2.1.1. Classes¶
Define a base context manager. |
17.1.1.8.1.2.1.2. 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: 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
- 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